Re: mutually referential (Pg 140 K&R2)
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Mon, 02 May 2005 10:03:00 GMT
Dave Thompson wrote:
>
> On Sat, 23 Apr 2005 15:23:02 +1000, Russell Shaw
> <rjshawN_o@xxxxxxxxxxxxxxxxxxxxx> wrote:
> <snip>
> > struct s *p declares p using an incomplete struct s type, which is later completed
> > with struct s {...}.
>
> Correct.
>
> > Incomplete types apply only to curly bracket things like
> > enums, unions, and structs iirc.
>
> YDNRC.
>
> 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 */
--
pete
.
- Follow-Ups:
- Re: mutually referential (Pg 140 K&R2)
- From: Keith Thompson
- Re: mutually referential (Pg 140 K&R2)
- References:
- Re: mutually referential (Pg 140 K&R2)
- From: Dave Thompson
- Re: mutually referential (Pg 140 K&R2)
- Prev by Date: Re: whats wrong with this pointer?
- Next by Date: Re: scanf(), Parameter Passing, and Character Arrays
- Previous by thread: Re: mutually referential (Pg 140 K&R2)
- Next by thread: Re: mutually referential (Pg 140 K&R2)
- Index(es):
Relevant Pages
|