Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/3/84; site wjh12.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!wjh12!kendall
From: kendall@wjh12.UUCP (Sam Kendall)
Newsgroups: net.lang.c
Subject: Re: Re: offsets in structures.
Message-ID: <527@wjh12.UUCP>
Date: Sat, 13-Oct-84 15:28:01 EDT
Article-I.D.: wjh12.527
Posted: Sat Oct 13 15:28:01 1984
Date-Received: Sun, 14-Oct-84 08:21:39 EDT
References: <393@orion.UUCP> <6080@mcvax.UUCP> <9386@watmath.UUCP>
Organization: Delft Consulting Corp., New York
Lines: 23

> A better expression, which is a bit closer to legit ...
> ... for getting the offset of a struct element,
>     (char *)(&((struct foo *)0)->element) - (char *)0
> ...
> (2) It is not at all clear that any operation on a NULL pointer other than
>     comparison and asignment is allowed. The above code does a pointer+int,
>     then a pointer difference, both using NULL pointers.
>                      Kevin Martin, UofW Software Development Group

(2) is correct because, it seems to me, if the reference manual defines
no operations on a null pointer besides copying, equality comparison,
and casting, then no other operations make sense (looking only at the
language rather than at implementations of it).

   The expression can be made portable, at least under UNIX, by
having
	extern end;
somewhere in a header file, and then replacing "0" in the expression by
"&end".  For maximum portability, of course, use a real object of type
struct foo in the expression.

	Sam Kendall	  {allegra,ihnp4,ima,amd}!wjh12!kendall
	Delft Consulting Corp.	    decvax!genrad!wjh12!kendall