Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!bloom-beacon!think!kulla!barmar
From: barmar@kulla (Barry Margolin)
Newsgroups: comp.lang.c
Subject: Re: Pointers and Offsets and Shared Memory Concerns
Keywords: pointers offsets shared memory
Message-ID: <30152@news.Think.COM>
Date: 26 Sep 89 23:38:28 GMT
References: <1989Sep25.175923.4125@DRD.Com>
Sender: news@Think.COM
Organization: Thinking Machines Corporation, Cambridge MA, USA
Lines: 19


Since you're using GCC, and GCC claims to be pANS-conforming, it
should have the "offsetof" operator.  Given a structure and an element
of the structure, this will return the offset of the element into the
structure.

I'm surprised, however, that GCC complains when you try

 offset = (char *)&(sdp->ElementOfInterest) - (char *)sdp;

The operands to the - operator are both char*, and they both point
into the same object, so it should be OK to subtract them.  The pANS
defines the meaning of subtraction of pointers within the same object,
so the above should be portable.

Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar