The offsetof macro
T. William Wells
bill at proxftl.UUCP
Mon Aug 29 09:20:21 AEST 1988
In article <16490006 at hpcllca.HP.COM> walter at hpcllca.HP.COM (Walter Murray) writes:
: 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?
There isn't any portable way that I can think of. I wouldn't be
surprised if that is why it is defined in a header file where the
compiler is free to define it any way it wants. For example, it
could be defined as:
#define offsetof(type,mem) __offsetof_kludge(type,mem)
and, could then treat __offsetof_kludge somewhat as it might
treat sizeof.
---
Bill
novavax!proxftl!bill
More information about the Comp.std.c
mailing list