Article View: comp.std.c
Article #1758Re: [m]allocation question
From: Stephen Clamage
Date: Sat, 29 Sep 1990 17:43
Date: Sat, 29 Sep 1990 17:43
19 lines
1165 bytes
1165 bytes
cameron@usage.csd.oz (Cameron Simpson,Uhmmm..???? Who knows) writes:
>I have been using the macro
> /* size of a field - may break under ANSI, but hasn't yet */
> #define fsizeof(type,field) sizeof(((type *)NULL)->field)
>for some time. I have recollections of remarks to the effect that the
>above locution could break under a conformant compiler. Could someone
>either correct me ("yes, Cameron, fsizeof() is ok") or re-iterate the
>explaination of why this macro can break, while sizeof(*t) is fine.
As long as "type" in not an incomplete type and "field" is not a bit
field, this is perfectly fine. The ANSI C standard explicitly
states that the expression argument of sizeof is not evaluated, so
NULL will not be derefrenced (which would be illegal).
--
Steve Clamage, TauMetric Corp, steve@taumet.com
Technical Details
Message-ID:
<466@taumet.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!taumet!steveReferences:
<13946@smoke.BRL.MIL> <871@usage.csd.unsw.oz.au>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: [m]allocation question Message-ID: <466@taumet.com> Date: 29 Sep 90 17:43:49 GMT References: <13946@smoke.BRL.MIL> <871@usage.csd.unsw.oz.au> Organization: Taumetric Corporation, San Diego Lines: 19