[m]allocation question

Stephen Clamage steve at taumet.com
Sun Sep 30 03:43:49 AEST 1990


cameron at 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 at taumet.com



More information about the Comp.std.c mailing list