Difficulty: Easy
Correct Answer: Error: cannot set bit field for float
Explanation:
Introduction / Context:
C bit-fields allow packing of integer data into specific numbers of bits inside a struct. The key restriction is that bit-fields must use integer types or _Bool, not floating types. This question tests recognition of that rule and the kind of error a compiler must emit.
Given Data / Assumptions:
Concept / Approach:
The C standard permits bit-fields with types _Bool, signed int, or unsigned int (and implementation-defined integer types). Floating-point types (float, double, long double) are not permitted for bit-fields.
Step-by-Step Solution:
Verification / Alternative check:
Changing the member to unsigned int f:2; or _Bool f:1; compiles and works, confirming the issue is the float bit-field, not sizeof or printf.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming any type can be used in a bit-field or confusing compiler extensions with standard C rules.
Final Answer:
Error: cannot set bit field for float
Discussion & Comments