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

Tom Stockfisch tps at sdchem.UUCP
Tue Dec 30 15:12:27 AEST 1986


In article <312 at hadron.UUCP> jsdy at hadron.UUCP (Joseph S. D. Yao) writes:
>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.

If this is legal, then the 4.3BSD C compiler is broken.  The file
below was sent to it,

	# define BLKSIZ	100

	typedef int	googol_t;

	/*###5 [cc] redeclaration of b%%%*/
	/*###5 [cc] illegal indirection%%%*/
	/*###5 [cc] warning: undeclared initializer name b%%%*/
	struct { googol_t a; } b[BLKSIZ/sizeof(b[0])];

as well as the much simpler

	/*###1 [cc] redeclaration of a%%%*/
	/*###1 [cc] illegal indirection%%%*/
	/*###1 [cc] warning: undeclared initializer name a%%%*/
	int	a[ sizeof(a[0]) ];

Can the legality of this construct be deduced from K&R?
Or is it an (obviously non-universal) extension?

|| Tom Stockfisch, UCSD Chemistry	tps%chem at sdcsvax.UCSD



More information about the Comp.lang.c mailing list