<div dir="ltr"><div>The paragraph in question (C++11) Is 4.7/4.  The second sentence covers the particular case in question.</div><div><br></div><div>If the destination type is bool, see 4.12. If the source type is bool, the value false is converted to zero and the value true is converted to one. </div><div><br></div><div>As for why, it can be useful to add a bool to an integer that is counting the number of times a function passed.  Then you can just write myBool += FunctionToTest(); rather than some conditional block.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 8:51 AM, James Molloy <span dir="ltr"><<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Guy,<br><br>C89 doesn't have the concept of "bool" - all comparisons return an int (or is it an unsigned int?) in the range [0,1].<div><br></div><div>C99 and C++ build on C89 so even though they have the concept of "bool", the type of a comparison was not changed.</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div><div><br></div><div>[Even though this C-language question seems easy enough for me to answer, I am certain that a true language lawyer will pipe up and tell me I'm wrong ;) ]</div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote">On Fri Feb 06 2015 at 4:37:11 PM Guy Maurel <<a href="mailto:guy.maurel@kde.org" target="_blank">guy.maurel@kde.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">Hello!<br>
<br>
Let say:<br>
    int a = 5;<br>
    int b = 7;<br>
    int i = 20;<br>
    if ((a  == b) + i) {<br>
        a = 15;<br>
    }<br>
My question is:<br>
The expression (a == b) gives a bool result.<br>
Why is it allowed to add a "bool" and an "int".<br>
<br>
Thanks<br>
--<br>
Guy Maurel<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>