I apologize ahead of time for my verbosity. Those who know me rarely involve
me in a conversation without having a pre-arranged escape plan.

>>Okay, the curmudgeon's gotta speak.
>>
>>Generally used to make a null pointer clear, NULL has been simply eye
candy
>>for the value 0.
>
>But recently, I've been finding places where a comparison against NULL
gives different result than against 0...
>...This sucks because I haven't figured out where it should be NULL and
where it should be 0

I agree. Precisely my point. NULL has been used incorrectly long enough that
it is differentiating 'C' dialects and breaking code.

Since some mistakenly define NULL as '(void*)0', you should only use NULL
with pointers, and never to mean zero in a mathematical sense. Are you using
NULL only with pointers and you still have problems? Are you only using the
assignment operators and the equality comparison?

One thing to try. Definitions of NULL are conditional on NULL being
undefined. If you superceed the definition of NULL with '#define NULL 0',
does your code work?


(Note: the following is agreement and commiseration, not argument :)



Some references:

K&R, 1st ed, pg 97
#define NULL 0

K&R, 1st ed, pg 192
"(due to nonportable pointer differences)...it is guaranteed that assignment
of the constant 0 to a pointer will produce a null pointer distinguishable
from a pointer to an object."

K&R, 2nd ed (ANSI), pg 102
"Pointers and integers are not interchangeable. Zero is the sole exception:
the constant zero may be assigned to a pointer, and a pointer may be
compared with the constant zero. The symbolic constant NULL is often used in
place of zero, as a mnemonic to indicate more clearly that this is a special
value for a pointer. NULL is defined in <stdio.h>."



A quick search of this machine finds some troubling disagreement:

Metrowerks\CodeWarrior\CW for Palm OS
Support\MSL\MSL_C\MSL_Common\Include\null.h
#define NULL    0L

Metrowerks\CodeWarrior\Palm OS Support\Incs\PalmTypes.h
#define NULL    0

sdk-3.5\include\PalmTypes.h
#define NULL    0

sdk-4\include\PalmTypes.h
#define NULL    0

cygwyn\usr\arm-palmos\include\sys\types.h
#define NULL ((void *) 0)

cygwyn\usr\H-i586-cygwin32\lib\gcc-lib\m68k-palmos\2.95.2-kgnd\include\stdde
f.h
#ifdef __GNUG__
#define NULL __null
#else   /* G++ */
#define NULL ((void *)0)
#endif  /* G++ */

cygwyn\usr\H-i586-cygwin32\m68k-palmos\include\string.h
#define NULL ((void *) 0)

cygwyn\usr\H-i586-cygwin32\m86k-palmos\include\sys\types.h
#define NULL ((void *) 0)

cygwyn\usr\include\locale.h
#define NULL    0

cygwyn\usr\include\stdio.h
#define NULL    0

cygwyn\usr\include\stdlib.h
#define NULL 0

cygwyn\usr\include\string.h
#define NULL 0

cygwyn\usr\include\sys\param.h
#define NULL            0L

cygwyn\usr\include\tiffio.h
#define NULL    0

cygwyn\usr\include\time.h
#define NULL    0

cygwyn\usr\include\win32api\windef.h
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif

cygwyn\usr\include\wchar.h
#define NULL    0



>Merry Christmas. 
Thank you very much. Merry Christmas to you, too.


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to