C 枚举的大型 c2hs 推断大小

Large c2hs-inferred size of C enum

在编写具有 5 个选项(使用 c2hs)的 C 枚举的 Storable 实例时,{# sizeof #} 宏 returns 4(即 4 个字节)。当 3 位就足够时,这不是非常浪费吗?这是否取决于内存字的大小?

枚举的大小是实现定义的。标准说:

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 ...

顺便说一句,在 C++ 中可以明确指定底层类型,例如:

enum E : int
{
    // ...
};