Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #8067

Re: Size of bool unspecified: why?

From "JBarleycorn" <jbnh2o@newsnet.org>
Newsgroups comp.lang.c++
Subject Re: Size of bool unspecified: why?
Date 2011-07-21 19:11 -0500
Organization A noiseless patient Spider
Message-ID <j0af6o$u4e$1@dont-email.me> (permalink)
References (2 earlier) <c8406a74-f3d9-4dd5-a3d7-3fb58c4d8ac0@l37g2000yqd.googlegroups.com> <j07eqo$qho$1@dont-email.me> <98ou27FaegU3@mid.individual.net> <j07s3r$hk6$1@dont-email.me> <4774c531-a003-4071-b5f4-f4acaa292682@d32g2000yqa.googlegroups.com>

Show all headers | View raw


James Kanze wrote:
> On Jul 21, 1:32 am, "JBarleycorn" <jbn...@newsnet.org> 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?
>
> First, I don't think it's unspecified.

This "unspecified" designation is something new to me. I don't really 
understand the point of it or how to determine if something is 
"implementation defined" or that.

> Implementation defined,
> on the other hand, is necessary in order for C++ to be
> implementable on all platforms.  (Reasonably, at least.)
>
>> How can bools be used in structs if every implementation can define
>> it differently?
>
> How can ints be used in structs if every implementation can
> define them differently.

There are a few different integral types, that are not boolean, from 
which to synthesize "fixed-width" integral types.

> On a given platform, if there is a C++
> API, all reasonable implementations will adhere to it.  If there
> isn't, then you can't link code compiled with different
> compilers.  Bool or no.

APIs are only half of the story.

>
>>>>> The size of all types is implementation defined (with
>>>>> a minimum size).
>
>>>>> And I don't see the issue with regards to structs.
>
>>>> C compatibility where layout, then, matters? Data transfer/storage.
>
>>> Then C++ added bool, C didn't have it so there was no layout
>>> compatibility to maintain.
>
>> Oh yeah! The 2 groups should have coordinated the introduction of
>> bool.
>
> But they didn't.  C wasn't interested (at the time).

Right, they didn't, but had they, they would have stood at least some 
chance at not implementing a boolean type that is broken.

>
>    [...]
>> I meant efficient in time, not space.
>
> The two are related.  Locality is an important issue on today's
> machines.

No need to be pedantic.

>
>> 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?
>
> It depends on how you use them, but I'd be very surprised if
> there were any use cases where 64 bit ints would be faster than
> 32 bit ints.

I was thinking that the register size and instructions on a 64-bit 
machine would somehow favor 64-bit operations.

>
>> Probably at least 3 things need to be eval'd:
>> argument passing performance, return value performance, arithmetic
>> performance.
>
> Plus about a dozen other parameters.

In usage, those probably cover enough of the territory. From a language 
implementation standpoint, some of those 12 others you have in mind may 
be important. What are the 12 others you have in mind?

>  In practice, the limiting
> factor for performance on today's machine is how many values fit
> in a cache line.

Do you know of any test suites to analyze such? That is, not the cache 
line thing, but the integral type thing, for the latter is the more 
abstract thing. 

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-16 05:33 -0500
  Re: Size of bool unspecified: why? BGB <cr88192@hotmail.com> - 2011-07-16 10:02 -0700
    Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-20 13:05 -0700
      Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-20 15:46 -0500
        Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 09:01 +1200
          Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-20 19:32 -0500
            Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 14:46 +1200
              Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-20 23:28 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 16:43 +1200
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 02:56 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-21 20:19 +1200
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 18:29 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 11:40 +1200
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 22:33 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 15:46 +1200
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 23:07 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 16:12 +1200
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-31 18:45 +1200
                Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:12 -0700
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:10 -0700
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 16:52 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-23 09:55 +1200
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:01 -0700
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:17 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-23 10:46 +1200
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-24 03:48 -0700
                Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-24 12:40 -0500
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-30 11:22 -0700
                Re: Size of bool unspecified: why? "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-07-31 02:33 +0200
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-30 11:34 -0700
                Re: Size of bool unspecified: why? "Alf P. Steinbach" <alf.p.steinbach:usenet@gmail.com> - 2011-07-25 04:46 +0200
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 07:23 -0700
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 18:52 -0500
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:24 -0700
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:22 -0500
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-23 10:51 +1200
                Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:17 -0700
                Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-22 04:26 -0500
            Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 02:09 -0700
              Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:11 -0500
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 11:58 -0700
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:48 -0500
            Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-21 08:41 -0700
              Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:14 -0500
                Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 12:01 -0700
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 17:51 -0500
        Re: Size of bool unspecified: why? Noah Roberts <dont@email.me> - 2011-07-20 16:57 -0700
          Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 07:29 -0700
            Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:24 -0500
              Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-22 12:33 +1200
                Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 22:42 -0500
        Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 01:59 -0700
          Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:42 -0500
            Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 12:20 -0700
              Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-22 18:21 -0500
  Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-16 22:23 -0500
    Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 00:07 -0500
      Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-17 17:15 +1200
        Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 00:24 -0500
      Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-17 02:02 -0500
        Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 03:02 -0500
          Re: Size of bool unspecified: why? Robert Wessel <robertwessel2@yahoo.com> - 2011-07-17 03:23 -0500
            Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 05:36 -0500
              Re: Size of bool unspecified: why? "James" <no@spam.invalid> - 2011-07-17 16:24 -0700
                Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-18 06:49 -0500
                Re: Size of bool unspecified: why? "James" <no@spam.invalid> - 2011-07-18 16:46 -0700
                Re: Size of bool unspecified: why? Ian Collins <ian-news@hotmail.com> - 2011-07-19 11:59 +1200
                Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-19 22:18 -0500
        Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-17 03:04 -0500
      Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:32 -0700
      Re: Size of bool unspecified: why? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-22 00:41 -0700
  Re: Size of bool unspecified: why? Juha Nieminen <nospam@thanks.invalid> - 2011-07-17 13:50 +0000
    Re: Size of bool unspecified: why? "MikeP" <mp011011@some.org> - 2011-07-18 06:50 -0500
      Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-20 13:06 -0700
    Re: Size of bool unspecified: why? Pawel Dziepak <pdziepak@quarnos.org> - 2011-07-21 12:59 +0000
      Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-21 07:11 -0700
        Re: Size of bool unspecified: why? "JBarleycorn" <jbnh2o@newsnet.org> - 2011-07-21 19:21 -0500
          Re: Size of bool unspecified: why? James Kanze <james.kanze@gmail.com> - 2011-07-22 12:28 -0700

csiph-web