sizeof(((struct_type *)0)->member_name)

Joseph S. D. Yao jsdy at hadron.UUCP
Mon Dec 29 13:33:00 AEST 1986


In article <7418 at utzoo.UUCP> henry at utzoo.UUCP (Henry Spencer) writes:
	[no attribution]
>> >> Can I do something like this:
>> >>     char a[sizeof(struct name *)0->element];

I hope someone said this while our news was down, but ... you may
not use tha above construct.  For precedence (and then also for
readability), the inner expression should be as in the Subject:
line:
	sizeof(((struct_type *)0)->member_name)

Some C compilers also haven't allowed arbitrarily complex or
semi-self-referential array size specifiers.  (The latter is,
e.g.:
	struct { googol_t a; } b[BLKSIZ/sizeof(b[0])];
.)  This is less of a problem these days, but may still be a
bug in some compilers.
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
			jsdy at hadron.COM (not yet domainised)



More information about the Comp.lang.c mailing list