Re: mutually referential (Pg 140 K&R2)
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Mon, 02 May 2005 19:24:19 GMT
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
.
- References:
- Re: mutually referential (Pg 140 K&R2)
- From: Dave Thompson
- Re: mutually referential (Pg 140 K&R2)
- From: pete
- Re: mutually referential (Pg 140 K&R2)
- From: Keith Thompson
- Re: mutually referential (Pg 140 K&R2)
- Prev by Date: Re: function pointers as function parameters
- Next by Date: Re: Differences between one-dimensional arrays in Java and C
- Previous by thread: Re: mutually referential (Pg 140 K&R2)
- Next by thread: Case insensitive search of substring in wide char
- Index(es):
Relevant Pages
|