offsetof

John F Carr jfc at athena.mit.edu
Thu Mar 7 09:28:54 AEST 1991


Is the following legal C?

	struct foo { struct bar { int a;} b;};
	offsetof(struct foo, a.b);

Section 4.1.5 of the standard doesn't explicitly disallow this, but I wasn't
able to find definitions elsewhere that would tell me if "a.b" is a
structure member or not.

The only compiler I've found that doesn't use some variant of

	#define offsetof(t,m) (size_t)&((struct t *)0)->m

for offsetof does not allow offsetof(struct foo, a.b).  Is it wrong?

--
    John Carr (jfc at athena.mit.edu)



More information about the Comp.std.c mailing list