Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!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 09:01:59 +1200 Lines: 48 Message-ID: <98ou27FaegU3@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net IxzX0sWGxxzuaaitzWp6xA0Pmi+1zJK75YFAPC7A1IkRuk8UrG Cancel-Lock: sha1:cU15IEMihMN0FDCz/nec/zP3zIo= 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++:8012 On 07/21/11 08:46 AM, JBarleycorn wrote: > James Kanze wrote: >> On Jul 16, 6:02 pm, BGB 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. >> 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. >>> IIRC, many compilers default to making them the same size as char, >>> or a single byte. this tends to be most convinient as, bigger, and >>> they are just wasting space, and smaller, as messing with bits is >>> awkward and costly (as well as compromising their direct >>> addressability, ...). >> >> 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. -- Ian Collins