Article View: comp.std.c
Article #2881Re: How soon can `sizeof (tagged_type)' be used?
From: Henry Spencer
Date: Mon, 13 May 1991 17:58
Date: Mon, 13 May 1991 17:58
20 lines
1229 bytes
1229 bytes
In article <5506@lupine.NCD.COM> rfg@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@zoo.toronto.edu utzoo!henry
Technical Details
Message-ID:
<1991May13.175830.7143@zoo.toronto.edu>Path:
arc1-ca.pugleaf.net!utzoo!henryReferences:
<5506@lupine.NCD.COM>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: How soon can `sizeof (tagged_type)' be used? Message-ID: <1991May13.175830.7143@zoo.toronto.edu> Date: Mon, 13 May 1991 17:58:30 GMT References: <5506@lupine.NCD.COM> Organization: U of Toronto Zoology