Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!gatech!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: Re: NULL pointer Message-ID: <3377@brl-tgr.ARPA> Date: Tue, 19-Nov-85 08:31:10 EST Article-I.D.: brl-tgr.3377 Posted: Tue Nov 19 08:31:10 1985 Date-Received: Thu, 21-Nov-85 04:04:54 EST References: <3359@brl-tgr.ARPA> Organization: Ballistic Research Lab Lines: 64 > But..... for a machine with non-zero null pointer representations > > > lo_func( ..., (int *)NULL, ... ); > > still doesn't work. What the callee routine gets is a pointer with an all-zero > representation.... which isn't a null pointer. The ONLY thing that does work is > > lo_func( ..., p=0, ....); > where p is a pointer of the requisite type! ... and > How many times do people have to go over this? Perhaps the problem is that > people don't understand what a cast does! > ... Ron Natalie has already replied restrainedly (for him) to this fool's posting, so I will simply FLAME HIM for CONFUSING THE POOR NOVICE by providing MISINFORMATION about what C type casts do. Dennis Ritchie about a year ago made one of his rare appearances in this newsgroup to set this matter straight, and it is covered quite well in all the standard references for C. A type cast has the same semantics as assignment to a temporary variable of the same type as the cast and use of that variable thereafter in the embedding context. In particular, this means that (gleep *)0 is a proper null pointer to a thing of type `gleep'; this is because assignment of the integer constant 0 to a pointer has those semantics. There is no assumption whatsoever about "bit patterns" in any of this! I try to be polite (for me) in these postings, but this yo-yo has done a disservice to those readers who do not already know the C language quite well and who might therefore think that he knows what he's talking about. To repeat the CORRECT information that I originally posted, so that the novice is not left with any misconceptions on the matter: If a function is declared func( ..., foo, ... ); int *foo; then invoking it as either func( ..., 0, ... ); or func( ..., (char *)0, ... ); is simply WRONG, and only works (by accident) on some implementations. The correct way to pass a null pointer to this function is func( ..., (int *)0, ... ); No #definition of NULL (as (char *)0, etc.) can in general keep the programmer from having to provide this explicit type cast when passing NULL as an argument to a function. (In X3J11-conforming implementations, the coercion will be done automatically if a function prototype declaration is in scope, but that is a separate matter from the original discussion.)