I don't think that f() is broken since you're not storing a 0 or a 1. See C99:
6.7.2.1 Structure and union specifiers
9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified
number of bits. If the value 0 or 1 is stored into a nonzero-width bit-field of type
_Bool, the value of the bit-field shall compare equal to the value stored.
Still g() with the explicit cast must be considered broken.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, the bitfield still has type _Bool. Thus when the assignment operator is used to store something into it, IMO it should be casted to _Bool first, and the result stored into the bitfield. C99, verse 1303: "In simple assignment (=), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand."
Philipp
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I use sdcc 2.9.7 #5879.
I don't think that f() is broken since you're not storing a 0 or a 1. See C99:
6.7.2.1 Structure and union specifiers
9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified
number of bits. If the value 0 or 1 is stored into a nonzero-width bit-field of type
_Bool, the value of the bit-field shall compare equal to the value stored.
Still g() with the explicit cast must be considered broken.
Well, the bitfield still has type _Bool. Thus when the assignment operator is used to store something into it, IMO it should be casted to _Bool first, and the result stored into the bitfield. C99, verse 1303: "In simple assignment (=), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand."
Philipp
Increasing priority, since bad code is silently generated.
Philipp
Fixed in sdcc revision #6768.
Philipp