1

When writing the Storable instance of a C enum that has 5 options (using c2hs), the {# sizeof #} macro returns 4 (i.e. 4 bytes). Isn't this extremely wasteful, when 3 bits would suffice? Does this depend on the size of a memory word?

ocramz
  • 816
  • 6
  • 18

1 Answers1

1

The size of enum is implementation-defined. The standard says:

6.7.2.2 Enumeration specifiers
...

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined ...

BTW, in C++ one could specify the underlying type explicitly, e.g.:

enum E : int
{
    // ...
};
AlexD
  • 32,156
  • 3
  • 71
  • 65