Re: Size of bool unspecified: why?
On Jul 21, 5:28 am, "JBarleycorn" <jbn...@newsnet.org> wrote:
"Ian Collins" <ian-n...@hotmail.com> wrote in message
news:98pi8pFroiU1@mid.individual.net...
On 07/21/11 12:32 PM, JBarleycorn wrote:
"Ian Collins"<ian-n...@hotmail.com> wrote in message
news:98ou27FaegU3@mid.individual.net...
On 07/21/11 08:46 AM, JBarleycorn wrote:
James Kanze wrote:
On Jul 16, 6:02 pm, BGB<cr88...@hotmail.com> wrote:
On 7/16/2011 3:33 AM, MikeP wrote:
Why is the size of 'bool' unspecified? That makes bools pretty
useless as struct members. If one foregoes bools in structs, why
not then specify that bools should be the size of int and thereby
likely to be fast to pass to and from functions? (Is it less
efficient to pass less-than-word-size integers because then they
have to be sign-extended or zero-extended, or any other reason?)
First, is size of bool unspecified? Or just implementation
defined?
Isn't that the same thing?
Not in terms of the standard. Implementation defined
things have to be defined by the implementation.
Why is "unspecified" necessary? Does anyone think that not
specifying the size of a bool is a good thing?
How can bools be used in structs if every implementation
can define it differently?
The same way ints can be used in structs when every implementation can
define them differently.
You can used fixed-width integers but there is no complementary bool
type.
The only fixed-width types I know are optional, and aren't
supported by implementations which don't have immediate hardware
support for them. Their use is fairly limited, and I can't
think of a case where I'd use them in a struct. (They are
convenient for certain operations, however, when their
restricted portability isn't an issue.)
bool is unusable in structs in many instances then.
You keep saying this, but it flies in the face of actual facts.
People use bool in structs all the time, with no problems.
Serialization is not a panacea, it's tedium.
You've mentionned serialization several times, but you've yet to
explain how the fact that the size of bool being implementation
defined affects it in any way. The internal representation
doesn't generally affect serialization. And it varies, not just
for bool, but for int.
--
James Kanze