Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!rutgers!mcnc!rti!xyzzy!hobbit.DG.COM!hunt From: hunt@hobbit.DG.COM (Greg Hunt) Newsgroups: comp.lang.c Subject: Re: Pointers and Offsets and Shared Memory Concerns Keywords: pointers offsets shared memory Message-ID: <1437@xyzzy.UUCP> Date: 29 Sep 89 00:40:23 GMT References: <30152@news.Think.COM> <1989Sep25.175923.4125@DRD.Com> Sender: usenet@xyzzy.UUCP Lines: 29 Try this (it works for me under GCC): #define MEMBER_OFFSET(mo_struct, mo_member) \ ((int32_type) (char_type *) & (((mo_struct *) 0) -> mo_member)) The following operation is allowed with MEMBER_OFFSET: typedef any_struct_type { .....member_name_within_struct; ..... } ANY_STRUCT_TYPE; = MEMBER_OFFSET (ANY_STRUCT_TYPE, member_name_within_struct); Note that the "structure type" passed MUST be a typedef structure name, not a typedef tag name, nor an instance of the structure. The member name must be within the structure, and can be any type except bit field. I define int32_type as long int and char_type as char. Hope it works for you. ------------------------------------------------------------------ Greg Hunt Internet: hunt@dg-rtp.dg.com Data General Corporation UUCP: {world}!mcnc!rti!dg-rtp!hunt RTP Software Development RTP, NC. 27713