top | item 33954652

(no title)

hvdijk | 3 years ago

Are they UB? What rule says they are? I would not be surprised by such a rule, but I am not aware of one.

discuss

order

ynik|3 years ago

A single-bit bitfield has only a sign bit, no value bits.

Prior to C23 there was no guarantee of two's complement, so it was possible that such a field could only hold the value 0.

hvdijk|3 years ago

True. And that still doesn't mean the behaviour is undefined, that just means the construct is not useful except on two's complement implementations. Which, even before C23, was all of them: the C23 change to require two's complement wasn't really meant to invalidate existing implementations, it was meant to reflect the reality that there were no other implementations worth considering. See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2218.htm, the only non-two's-complement implementation still in use that was found was very much a legacy-only thing for backwards compatibility where it was not expected that its users would want a modern C compiler anyway.

cryptonector|3 years ago

Oh, it might be implementation-defined rather than undefined behavior. Sorry, I'm not going to look through the spec right now for this.