J
James Kuyper
Kaz Kylheku said:["Followup-To:" header set to comp.lang.c.]I don't see how (var = true) can have a portability issue, where
var is of type bool, and the result is not converted in any way,
but only used as a control expression for some conditional thing
All this stuff with the assignment seems to be clouding the
central issue of this subthread, which is that if var has type
_Bool and internal representation B'00000010' what happens
when
if(var)
{
x = 1;
}
else
{
x = 0;
}
is executed? Does the standard allow bits 1:7 to be padding
bits ...
Yes. It also allows bits 0 and 2-7 to be padding bits. It's really quite
remarkable how little the C standard constrains the ways it can be
implemented.
... so that var tests as false and x = 0, or does it allow
all bits to be value bits ...
Also yes.
... so that var, being nonzero, tests
as true so x = 1, or does it allow B'00000010' to be a trap
value so that exceptional behavior can happen? ...
Yes, that is also permitted.
... Is any of
these behaviors required?
The width (number of value bits) of _Bool is not mandated by the
standard, though it must be >= 1 to satisfy 6.2.5p2. There is also
nothing preventing it from having trap representations - but the fact
that they are trap representations must be determined by padding bits.
As an unsigned type with N value bits (regardless of the value of N),
_Bool must be able to represent every value from 0 to 2^N-1, (6.2.6.2p1)
so for every possible combination of value bits, there must be at least
one non-trap representation containing that combination.