Re: mutually referential (Pg 140 K&R2)



Keith Thompson wrote:
>
> 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>

It's always distressing to learn something about C,
but that's why I'm here.
Thank you.

--
pete
.



Relevant Pages

  • Re: mutually referential (Pg 140 K&R2)
    ... >> 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: Earliest example of an incomputable real
    ... > enumeration of the reals, and there's no such thing as that. ... diagonalization is not well defined -- if it existed at all, ... are incomplete then ...
    (sci.math)
  • Re: enum safety
    ... 'Although variables of enum types may be declared, ... you declare declare a valid ...
    (comp.lang.c)
  • Re: enum base class
    ... public enum MyEnum1 ... Then I check all enumeration / their values the same way. ... You could cast all of the enums to int and declare the function with the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to do an enumeration in an interface?
    ... The enumeration has to be defined outside of the ... interface, and you can't declare that the interface has to declare an ... bool SomeMethod; ...
    (microsoft.public.dotnet.languages.csharp)