enum xyz;

Jim Blandy jimb@cygnus.com
Tue Aug 10 19:07:00 GMT 1999

I agree with Stan that we should simply remove the non-portable
construct, but just for entertainment:

> In fact, as I wrote this message, I came to realize that incomplete
> enums lose even on machines with single pointer representation.  For
> example, in the following code, a compiler that uses different storage
> sizes for enums would not know how much to copy.
>         enum foo;
>         struct bar {
>                 enum foo *bar;
>                 ...
>         };
>         struct baz {
>                 enum foo *baz;
>                 ...
>         };
>         {       
>                 ...
>                 *bar->foo == *baz->foo;
>                 ...
>         }
> And to think that some years ago I thought it was stupid to have
> incomplete structs and unions and not have incomplete enums...

The GCC manual says:

    Incomplete `enum' Types

       You can define an `enum' tag without specifying its possible values.
    This results in an incomplete type, much like what you get if you write
    `struct foo' without describing the elements.  A later declaration
    which does specify the possible values completes the type.

       You can't allocate variables or storage using the type while it is
    incomplete.  However, you can work with pointers to that type.

So your example isn't allowed, because you can't dereference a pointer
to an incomplete type.  And I'm a little confused about the problems
other folks have reported, because you're not allowed to declare
instances of an incomplete type, so their size can't matter.  The case
of incomplete enums is exactly parallel to that of incomplete structs:
you don't know what size the object is.


More information about the Gdb mailing list