Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jan 1998 19:47:18 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        dag-erli@ifi.uio.no (Dag-Erling Coidan Sm?rgrav)
Cc:        tlambert@primenet.com, asami@cs.berkeley.edu, jamie@itribe.net, jdevale@ece.cmu.edu, hackers@FreeBSD.ORG
Subject:   Re: FreeBSD Netcards
Message-ID:  <199801191947.MAA05774@usr08.primenet.com>
In-Reply-To: <xzp7m7wr0ig.fsf@hel.ifi.uio.no> from "Dag-Erling Coidan Sm?rgrav" at Jan 19, 98 03:39:35 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> Therefore, it is *perfectly correct* for the compiler to produce code
> that outputs "The value of a NULL character is 0" from the source code
> you give, since what you wrote is, in effect,
> 
>  		char    c = 0;

Just because the literal zero can be translated to the NULL pointer
does *NOT* mean that the NULL pointer can (or should) be translated
to a literal zero.

In point of fact, the reason my program prints what it prints is
because the behaviour is undefined by the compiler, and this is
what *happenS* to happen in this instance.

It is my argument that the compiler should issue warnings for undefined
behaviours.  After all it is *supposedly* a C compiler, and thus
*supposedly* has knowledge of the standards hard-coded into it.


> > Also, you're right that the standard allows for a non-zero value
> > for NULL.  I don't know of anyone who uses this; it's pretty much
> > in there to cause problems, like a lot of other "features", ie: the
> > assumption that certain optimizations are allowable unless they are
> > explicitly disallowed, etc..
> 
> The standard does *not* allow for a non-zero value of NULL. The
> standard very clearly states that the literal 0, when assigned to a
> pointer variable, evaluates to a NULL pointer. The standard does not,
> however, say anything about the internal representation of a NULL
> pointer. Wether or not a NULL pointer is all bits zero is
> implementation-defined.

As is wheter or not the "evaluation" you reference is run time or compile
time.  If it is compile time, then again, it makes sense to warn about
the conversion of a pointer type to a non-pointer type.


> > So pretty much until you fix the compiler, I'm going to keep my
> > terminology as fuzzy as the compiler's enforcement.
> 
> Again, nothing is wrong with the compiler. It's in perfect accordance
> with the ISO C standard. Your use of NULL in "a NULL string" or "the
> NULL character", however, is definitely incorrect. Instead, you should
> use "an empty string" and "the NUL character" (only one L),
> respectively.

My DEC ASCII chart that came with my old VT102 says "NULL" with two
"L"'s.  The three character representation of this is convention,
nothing more.

Further, I stated "NULL valued string", not "NULL string".  While
this is subject to interpretation, in context it was pretty obvious
that it could mean only one thing and continue to make sense.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801191947.MAA05774>