与常规枚举相比,c ++枚举结构的大小是否更大? [英] Are c++ enum structs bigger in size compared to regular enums?
问题描述
我正在嵌入式环境中开发,这个问题很重要。 Id'e喜欢使用枚举结构允许的类型安全性和范围限制,而不是费用代码膨胀。
否
语义的差异由编译器管理,因为它只涉及类型系统。
没有理由需要更多的存储空间,或者需要更多的指示。
您可以轻松地查看前者使用 sizeof
。
但是,我应该注意到C ++不保证任何这种类型的布局,除了说共享相同底层类型的两个枚举类型是layout-compatible( [C ++ 14:7.2 / 9]
)。
Are C++ enum structs (class) bigger in size compared to regular enums? i.e. what translates to more bytes of instruction code assuming they enumerate the same exact data?
I am developing in an embedded environment and this issue is kinda important. Id'e like to use the type-safety and scoping that enum structs allow, but not on the expense of code bloat.
No.
The difference in semantics is managed by the compiler, as it relates only to the type system.
There is no reason for more storage to be required, or for more instructions to be required.
You could easily check out the former on your actual types, using sizeof
.
However, I should note that C++ doesn't guarantee the layout of any such type, except to say that two enumeration types sharing the same underlying type are "layout-compatible" ([C++14: 7.2/9]
).
这篇关于与常规枚举相比,c ++枚举结构的大小是否更大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!