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]
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With