Xref: utzoo comp.lang.c++:6773 comp.std.c:2583 Newsgroups: comp.lang.c++,comp.std.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: references to dereferenced null pointers Message-ID: <1990Mar11.015305.28264@utzoo.uucp> Organization: U of Toronto Zoology References: <51083@microsoft.UUCP> <25EB8EE8.8462@paris.ics.uci.edu> <52081@microsoft.UUCP> <25F8D2FB.10981@paris.ics.uci.edu> Date: Sun, 11 Mar 90 01:53:05 GMT In article <25F8D2FB.10981@paris.ics.uci.edu> rfg@ics.uci.edu (Ronald Guilmette) writes: >...noted the obscure restriction that a null pointer must be >something created from "an integral constant expression with the value 0" >(see ANSI C standard 3.2.2.3). This could be an issue for both C and >C++, since it would seem to place in doubt the validity of the following: > > int nil () > { > return 0; > } > > ... > > void *vp; > > vp = (void *) nil (); This code is illegal in C, and always has been. There is no general relationship between the integer value 0 and the null pointer. An integer *constant* value equal to zero in a pointer context is automatically converted to a null pointer; this may be a non-trivial conversion, and is guaranteed valid only at compile time. The result of converting the integer value 0 to a pointer at run time is implementation-defined. -- MSDOS, abbrev: Maybe SomeDay | Henry Spencer at U of Toronto Zoology an Operating System. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu