Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!newstop!sun!imagen!atari!portal!portal!cup.portal.com!ts From: ts@cup.portal.com (Tim W Smith) Newsgroups: comp.lang.c Subject: Re: offsetof() operator. A tricky question. Message-ID: <28008@cup.portal.com> Date: 18 Mar 90 11:44:01 GMT References: <8ega02MX90Tk01@amdahl.uts.amdahl.com> <695@shuldig.Huji.Ac.IL> Organization: The Portal System (TM) Lines: 20 < The answer could be simple and I used several times, do this: < < struct astruct *ap; < < ap = NULL; < < offsetof_member0 = &ap->member0; /* zero offset */ < offsetof_member1 = &ap->member1; /* sizeof(member0) */ < < An offsetof() operator would be quite handy here. But until then you can < use this with a good portability of your programs. It IS simple. It is also wrong. If you want to have at least a small chance of working across different machines, try this: offsetof_member0 = (ulong)&ap->member0 - (ulong)ap; ... Tim Smith