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


Groups > comp.lang.c++ > #10573 > unrolled thread

Re: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010"

Started byPaul Brettschneider <paul.brettschneider@yahoo.fr>
First post2011-09-28 20:28 +0200
Last post2011-10-09 09:39 +0900
Articles 4 — 3 participants

Back to article view | Back to comp.lang.c++

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010" Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-09-28 20:28 +0200
    Re: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010" Edek <edek.pienkowski@gmail.com> - 2011-09-28 20:39 +0200
      Re: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010" Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-10-08 11:28 +0200
        Re: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010" Miles Bader <miles@gnu.org> - 2011-10-09 09:39 +0900

#10573 — Re: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010"

FromPaul Brettschneider <paul.brettschneider@yahoo.fr>
Date2011-09-28 20:28 +0200
SubjectRe: "bool const a( 5 )" in "Microsoft Visual Studio C++ 2010"
Message-ID<3b622$4e836745$506c0d9c$29532@news.chello.at>
Stefan Ram wrote:

>   . But didn't ISO/IEC 14882:2011 say in 4.12 Boolean
>   conversion about non-zero values:
> 
>       »any other value is converted to true.«
> 
>   ?

Oh yes! This has bitten me numerous times. Erroneously declared a function 
parameter as bool instead of int and got very strange results. :(

[toc] | [next] | [standalone]


#10574

FromEdek <edek.pienkowski@gmail.com>
Date2011-09-28 20:39 +0200
Message-ID<j5vpo3$ges$1@node2.news.atman.pl>
In reply to#10573
On 09/28/2011 08:28 PM, Paul Brettschneider wrote:
> Stefan Ram wrote:
>
>>    . But didn't ISO/IEC 14882:2011 say in 4.12 Boolean
>>    conversion about non-zero values:
>>
>>        »any other value is converted to true.«
>>
>>    ?
>
> Oh yes! This has bitten me numerous times. Erroneously declared a function
> parameter as bool instead of int and got very strange results. :(

I don't think that is the point; it is about the standard conversion
to bool, which many programmers rely on and which is well specified
in the standard.

Edek

[toc] | [prev] | [next] | [standalone]


#10730

FromPaul Brettschneider <paul.brettschneider@yahoo.fr>
Date2011-10-08 11:28 +0200
Message-ID<76c18$4e9017a9$506c0d9c$24473@news.chello.at>
In reply to#10574
Edek wrote:

> On 09/28/2011 08:28 PM, Paul Brettschneider wrote:
>> Stefan Ram wrote:
>>
>>>    . But didn't ISO/IEC 14882:2011 say in 4.12 Boolean
>>>    conversion about non-zero values:
>>>
>>>        »any other value is converted to true.«
>>>
>>>    ?
>>
>> Oh yes! This has bitten me numerous times. Erroneously declared a
>> function parameter as bool instead of int and got very strange results.
>> :(
> 
> I don't think that is the point; it is about the standard conversion
> to bool, which many programmers rely on and which is well specified
> in the standard.

Yes, I know what the point was. :) I was just complaining about this 
behaviour, which took me by surprise more than once, even though it is well 
documented.

Either treat bools like a normal integer type (with a size optimized for the 
use as flag, e.g. char for x86, int for RISC) or make the conversion non-
explicit. But I understand that the reasons for the standard compliant 
behaviour are historical and this has been discussed at length before. One 
of the terrible legacy things we have to live with.

[toc] | [prev] | [next] | [standalone]


#10749

FromMiles Bader <miles@gnu.org>
Date2011-10-09 09:39 +0900
Message-ID<87mxdbhub9.fsf@catnip.gol.com>
In reply to#10730
Paul Brettschneider <paul.brettschneider@yahoo.fr> writes:
> Either treat bools like a normal integer type (with a size optimized for the 
> use as flag, e.g. char for x86, int for RISC) or make the conversion non-
> explicit. But I understand that the reasons for the standard compliant 
> behaviour are historical and this has been discussed at length before. One 
> of the terrible legacy things we have to live with.

Wait, why is it "terrible"?  This conversion seems perfectly reasonable.

-miles

-- 
Americans are broad-minded people.  They'll accept the fact that a person can
be an alcoholic, a dope fiend, a wife beater, and even a newspaperman, but if
a man doesn't drive, there is something wrong with him.  -- Art Buchwald

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web