...
This noncompliant code depends on implementation-defined behavior. It prints either -1 or 255, depending on whether a plain int
bit-field is signed or unsigned.
Code Block | ||||
---|---|---|---|---|
| ||||
struct { int a: 8; } bits = {255}; int main(void) { printf("bits.a = %d.\n", bits.a); return 0; } |
...
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; } |
...