Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!apple!agate!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.unix.programmer Subject: Re: Nice() in Sys V.4 Message-ID: <11478@dog.ee.lbl.gov> Date: 26 Mar 91 20:26:35 GMT References: <318@secola.Columbia.NCR.COM> <1991Mar21.141753.28726@nncrcae.Columbia.NCR.COM> <11393@dog.ee.lbl.gov> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 60 X-Local-Date: Tue, 26 Mar 91 12:26:36 PST >In article <11393@dog.ee.lbl.gov> I wrote: >>It is impossible for p to have the `value ... zero' because p is a >>pointer---Pointers Are Not Integers---but this means we must guess at >>what was really meant. (Incidentally, I forgot to add that P.A.N.I. is an anagram for `pain', which is appropriate.) In article goehring@gnu.ai.mit.edu writes: >0, cast to any pointer type, is a valid pointer, by definition. Aye ... but once cast to a pointer type, it is no longer 0. This is kind of like saying `pi, cast to any integer type, is a valid integer'. It is, but you can no longer call it `pi'. It is important to note that nowhere is it stated that the bit pattern for any given `kind' of null pointer is all zeroes. In fact, there are machines on which: union { long l; int *ip; char *cp; } u1, u2; u1.ip = 0; u2.cp = 0; (void) printf(u1.l == u2.l ? "same\n" : "different\n"); prints `different'. A few of them have even run Unix derivatives (after fixing hundreds of incorrect pointer usages). The C language definition guarantees only that: * the integer constant 0, cast to any pointer type, produces a valid pointer value that compare unequal to the address of any valid of that type (including objects created via a successful call to malloc()); * when compared to the integer constant 0, a pointer of any type compares as equal if and only if that pointer was previously assigned the integer constant 0, or the integer constant 0 cast to the appropriate pointer type; * any two null pointers of any type, when cast to a common type, compare equal; and a few other minor points. It specifically does NOT say that any particular null pointer has the same bit pattern as any other particular null pointer, nor that any particular null pointer has the integer value 0. If you do not believe that the phrase `a zero pointer' is misleading, read comp.lang.c for a few weeks, or comp.unix.* for a few months or years, and watch for Frequently Asked Questions about null pointers or about the arguments to select(). -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov