I was surprised when doing the following that no assembly is produced for the Enums
:
I thought perhaps it would do something like:
Hello:
.byte 0
Goodbye:
.byte 1
It seems it only adds in the values when assigned to a var:
Why is this so? Why don't the 'enum values' get stored when declared (even if I set Hello=1
)? Example link: https://godbolt.org/z/xxnMvq.
An enum is not a variable, it is a type. The different enum labels are in fact constants. Being a type it requires no space in your final binary.
The compiler internally keeps a list of them and replaces every use of them with the constant they represent.
These values do however end up in the debugging info, if it is generated, so you can use them in your debugger.
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