Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site rabbit.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!rabbit!mjs
From: mjs@rabbit.UUCP (M. J. Shannon, Jr.)
Newsgroups: net.lang.c
Subject: Re: Re^3: offsets in structures.
Message-ID: <3252@rabbit.UUCP>
Date: Sun, 21-Oct-84 13:55:27 EDT
Article-I.D.: rabbit.3252
Posted: Sun Oct 21 13:55:27 1984
Date-Received: Mon, 22-Oct-84 01:58:39 EDT
References: <531@wjh12.UUCP>
Organization: AT&T Bell Laboratories, Murray Hill
Lines: 32

How about this fragment for a `portable' method of computing structure
offsets:

	f(sp)
	struct stuff *sp;
	{
		int	offset; /* may need to be long for some */

		offset = (char *) &sp->member - (char *) sp;
	}

If a (valid) pointer to the structure in question is not available,
it is easy (if costly on some machines) to make an auto:

	f()
	{
		struct stuff local_stuff;
		int	offset;	/* may need to be long... */

		offset = (char *) &local_stuff.member - (char *) &local_stuff;
	}

To my knowledge, this is the `ultimate' in portable offset calculation.
I would be extremely interested in hearing about any machines on which
either fragment fails to store the correct offset in `offset'.

	Yours in portability (just west of Outer Slobovia),
-- 
	Marty Shannon
UUCP:	{alice,rabbit,research}!mjs
	(rabbit is soon to die.  Does this mean alice is pregnant?  Yup!)
Phone:	201-582-3199