Newsgroups: rec.arts.int-fiction
Path: news.duke.edu!newsgate.duke.edu!nntp-out.monmouth.com!newspeer.monmouth.com!news.algonet.se!algonet!newspeer.clara.net!news.clara.net!news-hub.cableinet.net!uunet!ash.uu.net!dfw.uu.net!arb.uu.net!nyc.uu.net!world!buzzard
From: buzzard@world.std.com (Sean T Barrett)
Subject: [OT] Re: [Inform] Quick reference summary
Message-ID: <G72DJK.H95@world.std.com>
Date: Fri, 12 Jan 2001 19:16:31 GMT
References: <3A5B6FE5.DEDB1D25@tesco.net> <93kplc$94g$3@news.panix.com> <G70Fs0.Kr3@world.std.com> <93l24j$cbb$1@news.panix.com>
Organization: The World Public Access UNIX, Brookline, MA
Lines: 86
Xref: news.duke.edu rec.arts.int-fiction:82152

Andrew Plotkin  <erkyrath@eblong.com> wrote:
>Sean T Barrett <buzzard@world.std.com> wrote:
[reordered]
>> and if you're a good C programmer and always use NULL
>
>Stylistic issue. When I said what I said above, I didn't intend to
>remind only "good C programmers". I intended to remind anyone who's
>worked in C and might be confused.

Of course. There was an implication on my part against any
system of education where any programmer might have learned
that NULL "was" 0; since it's false in the long run, and not
actually helpful in the short run, people shouldn't be
learning it in the first place--and you yourself are potentially
contributing to the spread of what I consider misinformation,
hence my continuing this conversation in public.

But some of this may be a semantic distinction w.r.t
the word "NULL":

>> Except of course that in C NULL isn't 0 at all
>
>It may be 0 or (void*)0. Or, in an older world, (char*)0. I wouldn't
>say those are "not 0 at all".

Ok, if we're talking about NULL, the preprocessor symbol,
not "pointers which have value NULL", you're correct for
non-ANSI/ISO C, but that information is irrelevent, since it
is not applicable to pointers themselves (you could even
argue that since transitively NULL is not 0, it "is not 0
at all" in the sense of the normal use of "is") and
nobody does math on NULL itself. For ISO-C, if NULL
is defined as ((void *) 0), then I consider that "not
0 at all", quite definitely; see the example below.

If your claim was "programmers can use the number 0 to
mean NULL", then this is incorrect--although they can use
the literal symbol 0.

From a 1995 comp.lang.c faq (when people were still writing
non-ANSI C, but ANSI C existed):

  Confusion over the phrase "null pointer":
    http://www.eskimo.com/~scs/C-faq/q5.13.html
  Why you don't want to know what NULL is:
    http://www.eskimo.com/~scs/C-faq/q5.14.html

An example of the failure of NULL to be 0, transitively:

   void *p = NULL;
   int x = 0;
   if (p == x)
      puts("foo");
   if (p == NULL)
      puts("bar");
   if (x == NULL)
      puts("baz");

which legally print "foo\nbar\nbaz\n" or "bar\nbaz\n"
pre-ANSI; with ANSI/ISO the third comparison can also be false--
because in ANSI/ISO the (optional?) NULL macro definition
"((void *) 0)" isn't 0 at all--it's just a null pointer.

If you made me qualify exactly the verb to use instead of "is",
I would say:

   the number 0 can turn into a null pointer in certain contexts
   the null pointer is not guaranteed to turn into the number 0 in any context

[The "certain contexts" of the first line is when a literal 0 appears in
the source code in a pointer context.]

Both the context limitation on the first line, and the asymmetry
of the second line, make the assertion of equality of the two
values deeply misleading.

Even if you restrict your attention to "is" in the sense of the
"is defined to be" for the symbol NULL, you yourself said:

>It may be 0 or (void*)0.

And while true, those are the two things I was just saying it is
deeply misleading to equate to each other--hence to 0, hence
my claim "not 0 at all".

SeanB
