...
This compliant solution uses an unsigned int
bit-field and does not depend on implementation-defined behavior.:
Code Block | ||||
---|---|---|---|---|
| ||||
struct { unsigned int a: 8; } bits = {255}; int main(void) { printf("bits.a = %d.\n", bits.a); return 0; } |
...
CERT C++ Secure Coding Standard | INT12-CPP. Do not make assumptions about the type of a plain int bit-field when used in an expression |
ISO/IEC TR 24772:2013 | Bit Representations [STR] |
MISRA - C:2012 | Rule 12.7Rule 10.1 (required) |
Bibliography
[ISO/IEC 9899:2011] | Section 6.3.1.1, "Boolean, Characters, and Integers" |
...