wrote:
> I remember that this is a bad practice, but can not find a definitive
> resource that states it is bad and why. Can anyone help?
NULL evaluates to a integer constant with value 0. If you want to assign 0,
using 0 is a lot more clear. And if you use 0 not by the numeric value but
as some error/no error flag, the following will be more expressive:
const int MyFuncNoError= 0;
int myfunc ()
{
// ...whatever
return MyFuncNoError;
}
if (myfunc () == MyFuncNoError)
Using NULL you just confuse people by making it to think that myfunc returns
some type of pointer.
Some people use NULL for '\0', probably confusing it with the NUL name of
the char in ascii. This also causes a lot of confusion:
if (somestr != NULL && * somestr != NULL)
Looking at this you can think that somestr is a char * * instead of a char
*.
In a sentence: NULL is intended to be used with pointers, if you use it to
other things you just add confusion and get no benefit.
--
Salu2