LGTM: [skip ci]: Ambiguously signed bit-field member

Until C++11 bit fields with integral types should have explicit signedness only.
It is implementation specific whether an -typed bit field is signed, so there could be unexpected sign extension or overflow.

This means that if depending on the compiler int32_t is not explicitly defined as signed the UnitSignature structure may not work
as expected. Since C++14 this has changed and an int of a bit-field is always signed:
https://stackoverflow.com/questions/33723631/signed-bit-field-in-c14
This commit is contained in:
wmayer
2020-07-27 16:00:47 +02:00
parent 19c7fbd096
commit 826de6beff

View File

@@ -43,6 +43,9 @@ namespace Base {
#define UnitSignatureLuminousIntensityBits 4
#define UnitSignatureAngleBits 4
// Hint:
// https://en.cppreference.com/w/cpp/language/bit_field
// https://stackoverflow.com/questions/33723631/signed-bit-field-in-c14
struct UnitSignature{
int32_t Length:UnitSignatureLengthBits;
int32_t Mass:UnitSignatureMassBits;