与常规枚举相比,c ++枚举结构体积更大吗?(Are c++ enum structs bigger in size compared to regular enums?)

编程入门 行业动态 更新时间:2024-10-23 17:37:26
与常规枚举相比,c ++枚举结构体积更大吗?(Are c++ enum structs bigger in size compared to regular enums?)

与常规枚举相比,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]).

更多推荐

本文发布于:2023-08-04 13:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416092.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:更大   体积   常规   结构   enum

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!