The offsetof macro

Walter Murray walter at hpcllca.HP.COM
Sat Aug 27 07:36:49 AEST 1988


I think this may have been discussed a few months ago in comp.lang.c.
If so, would someone please mail or post the consensus that was
reached?

The offsetof macro is supposed to expand to an integral constant
expression.  There are strict rules about the operands and casts
that can be used in an integral constant expression, so, for
example, an expression containing "(type *)0" wouldn't be legal.
Using such an illegal expression in a place where an integral
constant expression is required, such as a case label expression,
would violate a constraint and would seemingly require a diagnostic
to be produced.

So what is a valid way to define offsetof?

Thanks

Walter Murray
All opinions expressed are my own



More information about the Comp.std.c mailing list