Ian said:
That argument doesn't make sense, given we have fixed with types, why
should the with of any natural type be fixed? The analogy with int
still applies. If I want a 32 bit signed type, I'll use int32_t.
Whether that is an int or a long under the hood is irrelevant.
Who often have you needed to know the size of bool? What do you do if
sizeof(int) isn't what the program expects?
Why would anyone expect sizeof(int) to be anything specific? int is not
an issue. The fixed-width sizes are an issue, but you can test for it and
do whatever is necessary to maintain consistency.
You use a different type.
A different numeric type, which there are a number to choose from. Who
writes a program that doesn't have a header that tests for assumptions
based upon the platform?
If bool doesn't meet your expectations, you don't have the option to
change to a similar type of different width, because there is no similar
type of different width. You have to change compilers or something. *Or*,
avoid bool from the get go noting from the start that you can't rely on
the width of bool. What the current practice is across a wide variety of
compilers, or just the "major" ones, I don't know: that would be good
info and maybe some consolation, but bool does appear to be broken from
the get go.
Again, how often is the size of a natural type important?
*Very* often.
How often
in real code do you use a fixed width type?
*Very* often. *Very* much more often than using non-fixed-width integral
types.
I'm sure I use them more
than most because a lot of my work is on embedded platforms or
drivers.
Well there you go then.
I seldom use them anywhere else.
It isn't unspecified, it is implementation defined, just like int.
The same issue exists with int, *but* there are the alternative
fixed-width integral types and even when their weren't the fixed-width
types, there was still enough choice there to get what is desired. I use
a boolean class, where I can control the width and still get the behavior
of a boolean, for use in structs but I have to because built-in bool is
broken.
Thing go horribly wrong when you study the wrong subset.
So what would you do if 8 bits performed best on one platform and 32
on another?
I would use that information in choosing a design.
You would make the size implementation defined.
No, not likely for then bool would be eliminated from a lot of places
where it could be used to good effect. I think multiple-width boolean
types can be made to work, but the complexity is not worth it, so 1-byte
bools, even though there may be a performance penalty on most platforms,
are probably the best choice. I have pretty much decided that where a
"fast bool" is needed it's a profile/optimizaation thing and trying to
find an optimum boolean type size as the best compromise across a set of
platforms falls into the category of premature optimization. Therefore,
the overriding concern is suitability for use as a struct field. So, my
boolean class uses a 1-byte type as the underlying type.