Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Size of bool unspecified: why? Date: Thu, 21 Jul 2011 16:43:04 +1200 Lines: 71 Message-ID: <98pp2qFroiU2@mid.individual.net> References: <98ou27FaegU3@mid.individual.net> <98pi8pFroiU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net h6wsOi7RcOB8rkTZgoGxnQyK0KEGBFb47wIkZaBD+BJvS5Yw47 Cancel-Lock: sha1:8iqPgMRX4BEQTY1ot2glgv+fXc4= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:8022 On 07/21/11 04:28 PM, JBarleycorn wrote: > "Ian Collins" wrote in message > news:98pi8pFroiU1@mid.individual.net... >> On 07/21/11 12:32 PM, JBarleycorn wrote: >>> "Ian Collins" wrote in message >>> news:98ou27FaegU3@mid.individual.net... >>>> On 07/21/11 08:46 AM, JBarleycorn wrote: >>>>> James Kanze wrote: >>>>>> 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. bool is unusable in structs in many instances then. Serialization > is not a panacea, it's tedium. The only places where sizeof(bool) matters it will be defined. >>>>>> A bool is required to be addressable; sizeof(bool) is also >>>>>> required to return an integral value. So a bool can't be >>>>>> smaller than a char. On a byte addressable machine, there's >>>>>> also no reason to make them bigger, >>>>> >>>>> Efficiency? >>>> >>>> Maybe, but efficiency isn't only dependent on size. If it were, we'd >>>> be using 64 bit ints on 64 bit machines. >>>> >>> >>> I meant efficient in time, not space. Are not 64-bit ints indeed more >>> efficient (in time) than 32-bit ints, say on x86 vs. x64? Anyone have >>> a >>> good simple test for this? Probably at least 3 things need to be >>> eval'd: >>> argument passing performance, return value performance, arithmetic >>> performance. I can compare the 8-bit bool vs. a 32-bit int on my >>> machine, >>> but I don't have a 64-bit machine. >> >> Efficient in time can be the same as efficient in space. The most >> valuable resource on modern CPUs is the cache, the bigger a data type, >> the quicker the cache overflows. That's why performance of some >> applications is better built 64 bit and worse for others. >> > > I guess I'll just have to profile it myself and see if there is > significant difference. Define "it". What part of "performance of some applications is better built 64 bit and worse for others" didn't you get? -- Ian Collins