Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!psuvm!cunyvm!uupsi!grebyn!ckp From: ckp@grebyn.com (Checkpoint Technologies) Subject: Re: NULL question not in FAQ Message-ID: <1991Mar27.194101.1685@grebyn.com> Organization: Grebyn Timesharing References: <1991Mar26.235643.4498@ux1.cso.uiuc.edu> Date: Wed, 27 Mar 1991 19:41:01 GMT In article <1991Mar26.235643.4498@ux1.cso.uiuc.edu> phil@ux1.cso.uiuc.edu (Phil Howard KA9WGN) writes: >Given that the compiler is supposed to translate the constant "0" to the >appropriate value for a NULL pointer on the machine type, how does one >get a pointer value whose representation happens to be all zeroes, but >is a non-NULL pointer? void some_func(void) { int **ip; ip = (int **) calloc(sizeof(int *), 1); ... And now, *ip is a pointer whose representaiton is all-bits-zero, which of course is not guaranteed to be NULL, but *probably is on your implementation. Most architectures are not capable of distinguishing between a pointer representation of all-bits-zero, and a null pointer. But you as a programmer should make this distinction. And, if I might restate the rest, for brevity... I am comfortable with the idea that 0 may be transformed into the null pointer value. However, the FAQ says that the *compiler* translates the integer 0 *constant* into the null pointer. It says nothing about transforming, at run time, integer zero values which may be in an object. Therefore, the following is not guaranteed to give me a null pointer: int i = 0; char *p = (char *)i; So is it correct to interpret this code as unportable? -- First comes the logo: C H E C K P O I N T T E C H N O L O G I E S / / ckp@grebyn.com \\ / / Then, the disclaimer: All expressed opinions are, indeed, opinions. \ / o Now for the witty part: I'm pink, therefore, I'm spam! \/