references to dereferenced null pointers

Roberto Shironoshita roberto at ssd.csd.harris.com
Sat Mar 17 04:04:44 AEST 1990


In article <1623 at argus.UUCP> ken at argus.UUCP (Kenneth Ng) writes:
> I'm confused, is a non zero NULL pointer valid or not?  I'm not asking if
> it will break 90% of the programs out there that use 0 instead of NULL.
> On a 370 here I'd love to define NULL as -1 because it will cause an
> immediate addressing exception if it is referenced.  But, I was told that
> NULL is defined as always being the value zero.

The Dec. 88 draft states that <stddef.h> defines the macro NULL, which
expands to an implementation-defined null pointer constant (section 4.1.5).

\begin{quote}
	An integral constant expression with the value 0, or such an
	expression cast to type void *, is called a _null pointer
	constant_. (...)
\end{quote}


So the implementation has two choices:

	#define NULL	0
or
	#define NULL	(void *)0

(where '0' stands for an integral constant expression that evaluates
to 0).

Your compiler is free to use whatever address it pleases when
translating code, so long as the program does not consider it a
valid address.  Note that dereferencing a NULL pointer causes
undefined behavior.
--
                               ||   Internet: shirono at ssd.csd.harris.com
     Roberto Shironoshita      ||
      Harris Corporation       ||             ...!novavax-\
   Computer Systems Division   ||   UUCP:                  -!hcx1!shirono
                               ||             ...!uunet---/
DISCLAIMER: The opinions expressed here are my own; they in no way reflect the
            opinion or policies of Harris Corporation.



More information about the Comp.std.c mailing list