int x = 0xFFFFFFFF; // packed bits of information
#define BIT_FIELD 0x02000000 // some high-order bit that we want to check
FlatBufferBuilder fbb;
FooBuilder foo_builder {fbb};
foo_builder.add_boolean_value(x & BIT_FIELD); // Whoops, stores '0'
This would not be an issue if add_boolean_value took an argument of type bool, as the compiler would then cast any non-zero integer value to true.
If I have the table
Then I get C++ generated code including:
This allows for very easy mistakes like:
This would not be an issue if
add_boolean_value
took an argument of typebool
, as the compiler would then cast any non-zero integer value totrue
.