Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当编写Storable具有 5 个选项的 C 枚举实例时(使用 c2hs),{# sizeof #}宏返回 4(即 4 个字节)。当 3 位就足够时,这不是非常浪费吗?这是否取决于内存字的大小?
Storable
{# sizeof #}
枚举的大小是实现定义的。标准说:
6.7.2.2 枚举说明符... 每个枚举类型应与char有符号整数类型或无符号整数类型兼容。类型的选择是实现定义的......
6.7.2.2 枚举说明符...
每个枚举类型应与char有符号整数类型或无符号整数类型兼容。类型的选择是实现定义的......
char
顺便说一句,在 C++ 中,可以明确指定底层类型,例如:
enum E : int { // ... };