What C compilers have non-zero null pointers?

Roger House roger at everexn.uucp
Wed Jul 11 13:07:58 AEST 1990


In <422 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:

>                             ...  "The assignment is a pure copy
>operation, with no conversion."  This means that in:
>	int i;
>	char*p;
>	i = 0;
>	p = i;
>the value assigned to p is the same bit pattern as i (which needs
>to be long on some machines, of course).    ... 

I don't know about the Bible, but the ANSI C standard does NOT say that p = i
is a pure copy.  Page 37 of the standard Rationale says:

	Since pointers and integers are now considered incommensurate,
	the only integer that can be safely converted to a pointer is
	the constant 0.  The result of converting any other integer to
	a pointer is machine dependent.

Also, p38 of the standard itself says:

	An integral constant expression with the value 0, or such an
	expression cast to type void *, is called a null pointer con-
	stant.  If a null pointer constant is assigned to or compared
	for equality to a pointer, the constant is converted to a 
	pointer of that type.  Such a pointer, called a null pointer, is
	guaranteed to compare unequal to a pointer to any object or
	function.

Note the term "integral constant expression".  In your example, i is not
a constant expression, so the result of p = i is machine dependent.

						Roger House



More information about the Comp.lang.c mailing list