Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.std.c Subject: Re: offsetof (was [m]allocation question) Message-ID: <469@taumet.com> Date: 3 Oct 90 15:52:53 GMT References: <1990Sep30.192325@objy.objy.com> Organization: Taumetric Corporation, San Diego Lines: 20 peter@objy.objy.com (Peter Moore) writes: >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. But offsetof is supplied by the compiler implementor, and whatever is supplied must work with the implementation. There is no guarantee that vendor A's offsetof will work with vendor B's compiler. That is why it is part of the standard header supplied with the compiler. You simply #include and use offsetof. Your code is guaranteed to work with any conforming implementation. There is no guarantee that YOU can write a portable offsetof. -- Steve Clamage, TauMetric Corp, steve@taumet.com