Igor Mozolevsky wrote:
> technical question, why is NULL defined as:
> #define NULL 0
> instead of
> #define NULL ((void*)0)
The best definition of NULL
in standard C is ((void *)0)
in standard C++ is 0
(read the respective FAQs if you disagree), and particular compilers can
do even better in C++ (see for example m68k-palmos-gcc's stddef.h), so the
best (standard) coding in PalmTypes.h would be
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
I attempted to get this done during development of the 4.0 SDK.
Unfortunately, due to sloppy existing code, it's not as easy as it appears.
IIRC the biggest problem was LocalIDs. A zero value for a LocalID indicates
a non-existent database or an error of some kind. Because a LocalID is not
a pointer, the correct way to write this is 0, not NULL. (If PalmTypes.h
declared something like NULL_LOCALID, that would perhaps be even better.)
Unfortunately, lots of existing code (e.g., in the Palm OS source code)
contains things like
mylocalid = NULL;
which would be a syntax error in C with C's best definition of NULL.
I fixed a lot of these place in the ROM to use 0 instead of NULL, but
couldn't get all of them and certainly couldn't affect other developers'
code. Rather than break existing third party code that misused NULL
like this, I left it alone.
Fortunately it is wrapped in #ifndef NULL in PalmTypes.h, so if you want
to get the additional type checking in C and in GNU C++ (and perhaps
other compilers), you can use the better definition from stddef.h by
#including <stddef.h> before #including any Palm OS SDK headers.
John
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/