Xref: utzoo comp.lang.c:14096 comp.lang.c++:1985 Path: utzoo!utgpu!watmath!rbutterworth From: rbutterworth@watmath.waterloo.edu (Ray Butterworth) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Re: offsetof (was: Re: Something new for C?) Keywords: offset of vars within structures Message-ID: <22164@watmath.waterloo.edu> Date: 15 Nov 88 16:29:01 GMT References: <73@dsoft.UUCP> <481@njsmu.UUCP> <26740@ucbvax.BERKELEY.EDU> Organization: U of Waterloo, Ontario Lines: 22 In article <26740@ucbvax.BERKELEY.EDU>, jas@ernie.Berkeley.EDU (Jim Shankland) writes: > On such machines, you must have an instance of the structure: > struct mumble foo; > int mem_offset = (char *)(&foo.member) - (char *)(&foo); > Sigh. The things you have to put up with in the portability trenches. The same argument applies for the alignof macro: #define alignof(type) /* assumes double is max aligned */ \ ( (char*)&(((struct {double _d; char _c; type _t;}*)0)->_t) \ - (char*)&(((struct {double _d; char _c; type _t;}*)0)->_c) ) which is equally non-portable, but for some reason the Committee chose not to make this macro part of the Standard even though alignof() seems to be more useful (to me at least) than offsetof(). > This is about the 10,000th reason that we need ANSI C *now*. And this is one more reason why "ANSI C now" still isn't good enough.