Xref: utzoo comp.lang.c:13890 comp.lang.c++:1902 Path: utzoo!attcan!uunet!lll-winken!arisia!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Re: Something new for C? Keywords: offset of vars within structures Message-ID: <646@quintus.UUCP> Date: 8 Nov 88 08:41:25 GMT References: <73@dsoft.UUCP> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 19 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: This is one fo the things that has been easy to do for a long time. If you're using a UNIX(tm) system, you may already have a header file /usr/include/struct.h, which defines fldoff(Structure_TAG, Field_Name) fldsiz(Structure_TAG, Field_Name) Modulo parens: fldoff(Tag, Field) = ((int) &((struct Tag *)0)->Field) fldsiz(Tag, Field) = (sizeof ((struct Tag *)0)->Field) This may give trouble on some 80*86 C compilers. ANSI C will have an "official" offsetof macro. I couldn't find the file on a V.3 '386 system, but the macros worked fine.