Article View: comp.std.c
Article #1773Re: offsetof (was [m]allocation question)
From: Stephen Clamage
Date: Wed, 03 Oct 1990 15:52
Date: Wed, 03 Oct 1990 15:52
20 lines
1211 bytes
1211 bytes
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 <stddef.h> 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
Technical Details
Message-ID:
<469@taumet.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!taumet!steveReferences:
<1990Sep30.192325@objy.objy.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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