Re: mutually referential (Pg 140 K&R2)



pete <pfiland@xxxxxxxxxxxxxx> writes:
> Dave Thompson wrote:
[...]
>> Forward declared struct and union tags are incomplete, until (the end
>> of) the full definition (if any). You can't forward declare an enum
>> tag; technically an enum type is incomplete from its type-specifier to
>> its closing brace, but this only means you can't use sizeof(enum foo)
>> as one of its own values which seems pretty silly anyway.
>
> I think you can. The enum type is complete,
> that is to say that it's type size is known at compile time,
> even if it's values haven't been specified.
>
> /* BEGIN new.c */
>
> #include <stdio.h>
>
> int main(void)
> {
> enum foo {Zero = sizeof (enum foo), One};
> enum bar;
>
> printf("sizeof (enum bar) is %lu bytes\n.",
> (long unsigned)sizeof(enum bar));
> return One - Zero - 1;
> }
>
> /* END new.c */

No. C99 6.7.2.2p4 says:

Each enumerated type shall be compatible with char, a signed
integer type, or an unsigned integer type. The choice of type is
implementation-defined, but shall be capable of representing
the values of all the members of the enumeration. The enumerated
type is incomplete until after the } that terminates the list of
enumerator declarations.

A footnote says:

An implementation may delay the choice of which integer type until
all enumeration constants have been seen.

If your compiler accepts the above code (in conforming mode), it's
probably broken. <OT>gcc doesn't.</OT>

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: mutually referential (Pg 140 K&R2)
    ... Keith Thompson wrote: ... >>> Forward declared struct and union tags are incomplete, ... You can't forward declare an enum ... > the values of all the members of the enumeration. ...
    (comp.lang.c)
  • Re: enum safety
    ... 'Although variables of enum types may be declared, ... you declare declare a valid ...
    (comp.lang.c)
  • Re: Enum Names
    ... enumeration, so you can declare a data type of that enumeration, or you can ... other words if I have a value of 2 I want the corresponding "secondKey" ... Public Enum MyEnum ...
    (microsoft.public.excel.programming)
  • Re: Custom Attributes, Shared methods, Derived classes and reflection
    ... description associated with an enum value. ... enumeration value will give you the name as defined by the enumeration, ... Dim fi As FieldInfo = value.GetType.GetField ... Public Shared Function GetEnumValue ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Custom Attributes, Shared methods, Derived classes and reflection
    ... description associated with an enum value. ... enumeration value will give you the name as defined by the enumeration, ... Dim fi As FieldInfo = value.GetType.GetField ... Public Shared Function GetEnumValue ...
    (microsoft.public.dotnet.languages.vb)