Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/5/84; site mordor.UUCP
Path: utzoo!linus!philabs!cmcl2!seismo!ut-sally!mordor!jdb
From: jdb@mordor.UUCP (John Bruner)
Newsgroups: net.lang.c
Subject: Re: offsets in structures.
Message-ID: <6542@mordor.UUCP>
Date: Thu, 11-Oct-84 15:03:09 EDT
Article-I.D.: mordor.6542
Posted: Thu Oct 11 15:03:09 1984
Date-Received: Fri, 12-Oct-84 06:12:19 EDT
References: <393@orion.UUCP> <5172@brl-tgr.ARPA>
Organization: S-1 Project, LLNL
Lines: 27

A problem with expressions like

	&((foo *)0)->bar 

(which I confess I have used myself) is that (foo *)0 is NOT a pointer
whose value is zero, it is a special case -- the NULL pointer.  The
two are identical only if your machine represents NULL as an integer
zero.  If your machine has a special representation for NULL/nil
pointers (e.g.  if it is a tagged architecture with a special NULL/nil
pointer tag) then (foo *)0 and (int)0 are distinct.  The above
expression is based upon the use of (foo *)0 as a pointer to zero,
not as the NULL pointer.

I believe that the above expression should be an illegal attempt to
perform address calculation using NULL.  Consider the following
"equivalent" code sequence on a machine for which NULL is not
represented as an integer zero; the address calculation here will blow
up, since "x" is assigned the NULL pointer, not a pointer to zero:

	foo *x;

	x = (foo *)0;
	... = &x->bar;
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb@mordor.ARPA [jdb@s1-c]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!decvax!decwrl!mordor!jdb