Xref: utzoo comp.lang.c++:6797 comp.std.c:2601 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: <1990Mar13.175253.15134@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> <1990Mar11.015305.28264@utzoo.uucp> <1990Mar11.222634.2701@almira.uucp> <1990Mar12.175613.12082@utzoo.uucp> Date: Tue, 13 Mar 90 17:52:53 GMT In article <1990Mar12.175613.12082@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >>... in K&R First edition, >>page 97, there is an explicit example which 0 is returned by a function >>returning a pointer to a character... > >K&R1 was kind of sloppy about this, partly because the pdp11 let you get >away with a lot... Oops, I goofed. (Yesterday was a bad day...) There is no problem with this. The function is known to return pointer to character, so the "return(0)" [actually "return(NULL)", prefaced by "#define NULL 0"] gets compiled as if it were "return((char *)0)" and everything is fine. By the time the value reaches the caller, it has already been converted to a pointer. Automatic conversion in "return" has been in the language since well before K&R1 (I can remember when it arrived, but that was a *long* time ago). On closer inspection of K&R1, at the prodding of a friend, no, K&R1 is *not* sloppy about this. I can't find any instance where the rules are being violated. Conversion of zero to pointer is always conversion of the constant 0. -- MSDOS, abbrev: Maybe SomeDay | Henry Spencer at U of Toronto Zoology an Operating System. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu