S
Simon Elliott
I have some legacy C++ code which requires some enums to be 1 or 2
bytes in size.
I'd ideally like to be able to specify that a few carefully selected
enums are a particular size.
By default, g++ seems to create enums of 4 bytes in length, unless I
use the -fshort-enums option. I don't much want to use this all or
nothing approach in case it breaks library code etc, and there's no
guarantee that other compilers have a comparable option in any case.
I could of course replace the enums with unsigned char or unsigned
shorts, but I wonder if there's a more elegant C++ solution, Is there
any way I can create a class containing an unsigned char or unsigned
short, but with the semantics of an enum?
bytes in size.
I'd ideally like to be able to specify that a few carefully selected
enums are a particular size.
By default, g++ seems to create enums of 4 bytes in length, unless I
use the -fshort-enums option. I don't much want to use this all or
nothing approach in case it breaks library code etc, and there's no
guarantee that other compilers have a comparable option in any case.
I could of course replace the enums with unsigned char or unsigned
shorts, but I wonder if there's a more elegant C++ solution, Is there
any way I can create a class containing an unsigned char or unsigned
short, but with the semantics of an enum?