how about sizeof(((type *)1)->member) ?
Richard O'Keefe
ok at cs.mu.oz.au
Mon Oct 30 14:26:51 AEST 1989
The problem is how to replace
sizeof (((struct foo *)(0))->member)
in an ANSI-portable way.
Since malloc() must return a pointer which satisfies all alignment
requirements, could we not use
#define fieldsize(Foo,Member) sizeof \
(((struct Foo *)malloc(sizeof (struct Foo)))->Member)
Since the expression isn't going to be evaluated, nothing will be allocated.
If it _were_ evaluated, the expression would be valid, so a compiler has
nothing to complain about, or has it?
More information about the Comp.lang.c
mailing list