Frederick said:
Think clearly. If I was really that lazy I wouldn't be on this newsgroup
writing code which provides me with no monetary gain.
I don't pretend to know your motives for posting. I'm just speaking
from experience as a designer and implementor.
Then "people" may expect undefined behaviour. I don't write functions to
be used by three year olds.
Yeah, we'd all want smart users of our code. We don't always get that.
And if we dismissed them as stupid you'd find that there are few
people using it. Even something as trivial as say zlib. Still gets
people asking "how do I make a gzip file" questions.
Not only that, but bugs do occur, robust code helps not only curb bugs
by not proceeding on errant paths but detect and report them to the
developer.
I always check the return of mallocs but I've still managed to slip an
unitialized pointer [well I calloc structures] to a function from time
to time. A simple check for NULL picks that up and I'm off to the
races.
I'm not sure if the same applies for C, but in C++, the decimal digit
characters are guaranteed to be sequential and in ascending order.
Can someone please clarify if this holds true for C?
Maybe that's true. I'd use a table anyways. in my ASN.1 IA5 and
Printable routines I have a table of chars and ints. That way
regardless of the mapping I can move from one to another easily and
portably.
Also the use of "inline" for that function is redundant. Smart
compilers will do it anyways and it isn't portable across all compilers
[yes, supporting non-standard compilers like MSVC and borland are often
desired features.]. Except for things like inlined ASM functions the
"inline" keyword is not terribly useful.
Or, wherever possible, I write my code so that it simply can't be
erroneous, for example:
int main(void)
{
int i = 54;
int j = i % 3;
FunctionThatWantsNumberBetweenZeroAndTwoInclusive( j );
}
I'm not saying all your functions have to be param checking. Just the
user exposed ones. Though as your code base increases in complexity
the checking becomes relevant again.
From my experience from my projects and the support email I get, most
people who can't get functions to work don't read the manual. A good
portion of the others are weak C programmers and don't understand
pointers and the like fully. A simple != NULL or other check may seem
to kill performance [hint: they don't] but are totally worth it.
Yes, in the calling function:
Calling function would be part of the users code. I thought I made it
clear there are a lot of weak developers?
Idealism is cool and all, that is, afterall, why I distribute my
projects [
http://libtomcrypt.com]. But if you want people to use your
code you have to deal with really shotty programmers.
Tom