How soon can `sizeof (tagged_type)' be used?

Henry Spencer henry at zoo.toronto.edu
Tue May 14 03:58:30 AEST 1991


In article <5506 at lupine.NCD.COM> rfg at lupine.ncd.com (Ron Guilmette) writes:
>Are either or both of these examples legal?
>
>enum E { red, green = sizeof (enum E), blue };
>struct S { int i; int j : sizeof (struct S); int k; };

I think neither.

In the first one, the argument of sizeof is meaningless, because E is not
declared until the end of the brace-enclosed list.  Enums, unlike structs
and unions, cannot be incomplete types.

In the second example, the struct type is incomplete until the
closing brace.  ANSI C is rather vague about where incomplete types can
be used, saying only "when the size of an object of the specified type
is not needed", with no explanation of what that *means*, but sizeof is
the one clear situation.
-- 
And the bean-counter replied,           | Henry Spencer @ U of Toronto Zoology
"beans are more important".             |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.std.c mailing list