Nice() in Sys V.4

Chris Torek torek at elf.ee.lbl.gov
Wed Mar 27 06:26:35 AEST 1991


>In article <11393 at 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.91Mar25143457 at gnu.ai.mit.edu>
goehring at 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 at ee.lbl.gov



More information about the Comp.unix.programmer mailing list