Path: utzoo!attcan!uunet!wuarchive!decwrl!sgi!llustig!objy!objy!peter From: peter@objy.objy.com (Peter Moore) Newsgroups: comp.std.c Subject: offsetof (was [m]allocation question) Message-ID: <1990Sep30.192325@objy.objy.com> Date: 1 Oct 90 02:23:25 GMT Sender: news@objy.com Reply-To: peter@objy.com Organization: Objectivity Inc. Lines: 20 The validity of sizeof((type *)->field)) is especially interesting given the sample (though carefully described as unportable) definitions of offsetof in the Rationale (4.1.5: pg 75): #define offsetof(type, field) (size_t)&(((type*)0)->field) This isn't going to work if sizeof((type *)->field) doesn't work. By the way, the above definition of offsetof always seemed like a bad one, since it makes the unnecessary assumption that the null pointer has a 0 bit-pattern. Now practically, that is probably true for almost all compilers, if only because there is so much code that implicitly depends on it. But wouldn't a more politically correct example be: #define offset(type, field) \ ( ((char *) &(((type *)0)->field)) - ((char *) 0) ) Peter Moore peter@objy.com