Xref: utzoo comp.lang.c:14121 comp.lang.c++:1996 Path: utzoo!attcan!uunet!husc6!mailrus!ames!amdcad!weitek!sci!auspyr!mick From: mick@auspyr.UUCP (Michael J. Andrew) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Re: Something new for C? Keywords: offset of vars within structures Message-ID: <13414@auspyr.UUCP> Date: 15 Nov 88 01:31:16 GMT References: <73@dsoft.UUCP> Reply-To: mick@auspyr.UUCP (Michael J. Andrew) Organization: Austec Inc., San Jose, Ca, USA Lines: 23 In article <73@dsoft.UUCP> root@dsoft.UUCP (Super user) writes: |Maybe I've missed something in C, but One of the things I've never found a way |to do and have always wanted, was a precompiler command to allow me to use |the offset of an item into a structure. for example: | |struct test { | long this; | int that; | char those[8]; |}; | | val = offset(test,that); Try the following: #define OFFSET(structure,field) ((int) &(((struct structure *)0)->field)) A useful trick which I'm afraid I cannot take credit for. Watch out for hardware with brain damaged (read "clever") addressing! -- ------------------------------------------------------------------------- Michael Andrew Sr. Systems Engineer Austec, Inc. San Jose CA. mick@auspyr.UUCP or amdahl!auspyr!mick (408) 279 5533