Is #define NULL 0L ok?
tjt at kobold.UUCP
tjt at kobold.UUCP
Tue Mar 13 03:26:16 AEST 1984
Using:
#include <stdio.h>
#undef NULL
#define NULL 0L
will fail on a machine with 16 bit pointers, 16 bit int's but 32-bit
longs (the pdp-11, for example). On the pdp-11, defining NULL as 0L
will cause two words to be pushed on the stack for as a function
argument while the called routine will only be expecting one word for
that argument.
As has been pointed out too many times to count, it is impossible to
define a generic null pointer in C: you have to cast 0 to the pointer
type when passing it as an argument. You can do this by including the
type cast in each use, or #define a null pointer for each pointer type
you use.
--
Tom Teixeira, Massachusetts Computer Corporation. Westford MA
...!{ihnp4,harpo,decvax}!masscomp!tjt (617) 692-6200 x275
More information about the Comp.lang.c
mailing list