T
Tim Rentsch
Peter Nilsson said:Tim Rentsch said:Ben Bacarisse said:_Bool is an unsigned type. ...
In any kind of arithmetic or comparison it will always be
promoted to an int since the two legal values of _Bool
always fit into and int.
To nitpick, C99 does not say that 0 and 1 are the only legal
values for bool, [snip elaboration]
Not said explicitly, but this does hold as a logical
consequence of the rules governing conversions.
But there are other ways to get a value into a _Bool than via a
conversion.
That's true but it doesn't change the result. The question is
what values can _Bool hold as documented values (ie, and not trap
representations),
My last assertion was that _Bool's integer promotion can potentially
be to unsigned int.
"An object declared as type _Bool is large enough to store the
values 0 and 1."[1] There is nothing stating that _Bool must only
have 1 value bit, just as UINT_MAX being at least 65535 is not a
statement that it can only be 65535.
and these are constrained by conversion rules to be only 0 and 1
That mearely constrains the values that result from conversion.
No, the conversion rules also have implications for what
values a _Bool can hold, not just for the output of a
conversion.
You haven't demonstrated it would be non-conforming.
True, I hadn't, but will (again) below...
True, but not the issue.
If it isn't a trap representation then all you can say is the value
is appropriate to the object type.
That, _and_ the implementation must conform to all the other
requirements given in the Standard. Consider the following
program:
_Bool a, b;
/* somehow give 'b' a value, not by assigning to it but *
* by some other means such as storing into it using an *
* unsigned character array. */
a = b;
The assignment operation converts the _Bool value of the
right-hand side to the type of the assignment expression, which is
also _Bool. By 6.3.1.2p1, the result of the conversion must be 0
or 1. By 6.3p2, the result of the conversion must also be the
same value as the pre-conversion value. These two conditions can
be satisfied simultaneously only if _Bool is constrained to just
two defined values (those being 0 and 1).
The Committee's Response in DR335 says _Bool has an implementation
defined width. Has there been any advance on that?
Something being implementation-defined isn't carte blanche;
whatever its definition is, the implementation still must
conform to the Standard's other requirements, which in this
case imply that the width must be one. As of n1570, all the
relevant sections - 6.3p2, 6.3.1.2p1, 6.5.16.1p2 - are all
exactly the same as in n1256 (except for one unrelated new
footnote having to do with converting NAN's to _Bool).