与常规枚举相比,C ++枚举结构(类)的大小是多少? 即什么转换为更多字节的指令代码假设他们枚举相同的确切数据?
我在嵌入式环境中开发,这个问题有点重要。 Id'e喜欢使用枚举结构允许的类型安全性和范围限制,但不是代码膨胀的代价。
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.
最满意答案
没有。
语义上的差异由编译器管理,因为它仅与类型系统有关。
没有理由需要更多存储空间,或者需要更多说明。
你可以使用sizeof轻松地检查出你的实际类型。
但是,我应该注意到C ++不保证任何这种类型的布局,除了说两个共享相同底层类型的枚举类型是“布局兼容”( [C++14: 7.2/9] )。
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]).
更多推荐
发布评论