Specifying the underlying enum type in g++
Axel Freyn
axel-freyn@gmx.de
Thu Sep 24 17:07:00 GMT 2009
Hello Jean-Claude,
On Thu, Sep 24, 2009 at 11:11:20AM -0400, Jean-Claude Gervais wrote:
> Hello,
>
> I am using gcc 4.1.2 and 4.3.2, looking for a way to specify the
> underlying type in a typedef enum declaration like so:
>
> typedef enum : unsigned char { first_tag, second_tag, third_tag }
> my_enum_type;
>
> The preceding statement compiles with visualc++ but not with g++
>
> Is there a way?
As far as I know, in the current C++ standard it is impossible to
specify the underlying type explicitely - that's an extension of Visual
C++.
Maybe you can use the compile-switch "-fshort-enums" of g++?
-fshort-enums
Allocate to an "enum" type only as many bytes as it needs for the
declared range of possible values. Specifically, the "enum" type
will be equivalent to the smallest integer type which has enough
room.
Alternatively, you have to try a more modern version of gcc. This
feature will be integrated in the upcoming C++-standard, so maybe g++
4.5 already supports it?
HTH,
Axel
More information about the Gcc-help
mailing list