argv[] terminated by a NULL pointer?

Henry Spencer henry at zoo.toronto.edu
Sat Jun 29 04:02:24 AEST 1991


In article <23292 at paperboy.OSF.ORG> dbrooks at osf.org (David Brooks) writes:
>|> On a system where the null pointer is represented by all bits one,
>|> the following statement:
>|> ((char *)0) == ((char *)-1) 
>|> would be true...
>
>Is this strictly true? 

No.  There is a *good chance* that the expression would evaluate to 1,
but no certainty.  The conversion of 0 to `char *' is required to yield
a null pointer.  What happens when you convert -1 to `char *' is
completely up to the implementation.  Remember that -1 is not necessarily
all-bits-one.  Even if it were, the conversion to pointer could legally
change it to something else.

(How might these things happen?  Well, on a one's-complement machine -1
is *not* all-bits-one.  Yes, there are ANSI C compilers on such machines.
As for the conversion to pointer, what happens if a pointer is longer
than an int?  Precisely where the int value gets put in the pointer
value, and how the other bits are filled in, is not defined by the
standard.  In practice, it would depend on what was most convenient
on that particular architecture, and putting the int in the low bits
and doing a sign extension is not the only possibility.)
-- 
Lightweight protocols?  TCP/IP *is*     | Henry Spencer @ U of Toronto Zoology
lightweight already; just look at OSI.  |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list