define sizes and explicit values for all enums #141
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds defined sizes (uint8_t or int8_t in one case) and explicit values to all our enums.
This is due to the work on I2CCommander, and the need to do serialisation/deserialisation of these values in binary format.
While in theory the C++ compiler would probably have generated stable values, making them explicit guarantees this, and is also a form of documentation (e.g. makes it easy to see which enum constant has byte value 0x04 when looking at a Wireshark capture).
in addition there is a subtlety that enums are usually ints e.g. (sizeof(enumtype)==4 on 32 bit MCUs) but if you don't specify it isn't guaranteed. So when serialising, you could wind up with different sizes for the enum types on different architectures (or maybe due to compiler settings). Also that makes them subject to endianness problems (ugh :-( ).
Luckily all our enums have <256 elements, so I have defined their size to 8bit integers which gets rid of all these problems.