Question 5.5

How should NULL be defined on a machine which uses a nonzero bit pattern as the internal representation of a null pointer?


The same as on any other machine: as 0 (or ((void *)0)).

Whenever a programmer requests a null pointer, either by writing ``0'' or ``NULL,'' it is the compiler's responsibility to generate whatever bit pattern the machine uses for that null pointer. Therefore, #defining NULL as 0 on a machine for which internal null pointers are nonzero is as valid as on any other: the compiler must always be able to generate the machine's correct null pointers in response to unadorned 0's seen in pointer contexts. See also questions 5.2, 5.10, and 5.17.

References: ANSI Sec. 4.1.5
ISO Sec. 7.1.6
Rationale Sec. 4.1.5


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback