Xref: utzoo comp.lang.c++:6848 comp.std.c:2624 Path: utzoo!attcan!uunet!snorkelwacker!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!novavax!hcx1!roberto From: roberto@ssd.csd.harris.com (Roberto Shironoshita) Newsgroups: comp.lang.c++,comp.std.c Subject: Re: references to dereferenced null pointers Message-ID: Date: 16 Mar 90 18:04:44 GMT References: <51083@microsoft.UUCP> <25EB8EE8.8462@paris.ics.uci.edu> <1990Mar12.175613.12082@utzoo.uucp> <1623@argus.UUCP> Sender: news@hcx1.SSD.CSD.HARRIS.COM Reply-To: shirono@ssd.csd.harris.com Lines: 38 In-reply-to: ken@argus.UUCP's message of 13 Mar 90 20:25:47 GMT In article <1623@argus.UUCP> ken@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 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@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.