[Eug-lug] LP64
Neil Parker
nparker at LLX.COM
Thu Jan 13 18:15:08 PST 2005
T. Joseph Carter wrote,
>I had someone insist that 0 was mandated to be acceptable in place of
>NULL. I pointed out that 0 is a valid address on some systems, and was
>answered that it was not a valid address in C, even on those systems.
>
>I tend to fix code which uses 0 where NULL is intended when I can, but
>there's so much of it exists!
If I remember correctly, it's C++ that mandates that 0 be assignable to any
pointer, and that the compiler must convert this into whatever internal
representation the platform uses for a pointer that will never point to
anything.
I don't think C has the same requirement, but I'm not sure what C99 has to
say on the subject.
I believe many modern UNIXes and UNIX-like OSes map the first page of
every process's address space as non-readable, so that following a null
pointer (or any other pointer that points to the first page) will force a
segmentation violation.
- Neil Parker
More information about the EUGLUG
mailing list