offsets in structures.

Morris Keesan keesan at bbncca.ARPA
Sat Oct 13 08:34:00 AEST 1984


>That's a broken compiler.  "(struct foo *)0" is of type "pointer to 'struct
>foo'", so adding 1 to it should make it point to the "next" object of type
>"struct foo".
>
>	 Guy Harris
>

As John Bruner has already pointed out, this is not at all broken behavior on
the part of the compiler.  Section 7.14 of the C Reference Manual (p. 192 in
K&R) says, " . . . it is guaranteed that assignment of the constant 0 to a
pointer will produce a null pointer distinguishable from a pointer to any
object."  This means that although "(struct foo *)0" is indeed of type
"pointer to 'struct foo'", it is guaranteed not to point to any object, so it
is meaningless to refer to the "next" object.
-- 
			    Morris M. Keesan
			    {decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan
			    keesan @ BBN-UNIX.ARPA



More information about the Comp.lang.c mailing list