Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: argv[] terminated by a NULL pointer? Message-ID: <1991Jun28.180224.9294@zoo.toronto.edu> Date: Fri, 28 Jun 1991 18:02:24 GMT References: <12187@hub.ucsb.edu> <14603@dog.ee.lbl.gov> <1991Jun28.052339.14611@ringer.cs.utsa.edu> <23292@paperboy.OSF.ORG> Organization: U of Toronto Zoology In article <23292@paperboy.OSF.ORG> dbrooks@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@zoo.toronto.edu utzoo!henry