<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 26, 2015 at 12:04 PM, Richard <span dir="ltr"><<a href="mailto:legalize@xmission.com" target="_blank">legalize@xmission.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
In article <<a href="mailto:E1YbBnb-00023F-6K@shell.xmission.com">E1YbBnb-00023F-6K@shell.xmission.com</a>>,<br>
<span class="">    Richard <<a href="mailto:legalize@xmission.com">legalize@xmission.com</a>> writes:<br>
<br>
> I think this is where the wording in the standard allows you to write:<br>
><br>
> if (sp) { ... } else { ... }<br>
><br>
> without having to write an explicit conversion to bool.  I didn't look<br>
> up the language of how the ternary expression interprets the<br>
> conditional expression.  I will do that and see what it says.<br>
<br>
</span>As I read the standard, the same interpretation is applied to<br>
conditions of if statements as is applied to the condition in a<br>
ternary operator:<br>
<br>
4. [conv]<br>
<br>
    "Certain language constructs require that an expression be converted<br>
    to a Boolean value.  An expression e appearing in such a context is<br>
    said to be contextually converted to bool and is well-formed if and<br>
    only if the declaration bool t(e); is well-formed, for some invented<br>
    temporary variable t (8.5)."<br>
<br>
5.16 [expr.cond]<br>
<br>
    "The first expression is contextually converted to bool (Clause 4)."<br>
<br>
6.4 [stmt.select]<br>
<br>
    "The value of a condition that is an initialized declaration in<br>
    a statement other than a switch statement is the value of the<br>
    declared variable contextually converted to bool (Clause 4)."<br>
<br>
So I would be in step with the standard if I replaced all expressions<br>
e with bool(e), but I'd like to avoid the unnecessary conversion where<br>
possible.<br></blockquote><div><br>Right - sorry, the issue I'm trying to address isn't that bool(e) isn't valid for all the cases where you're doing this conversion (it is) but it's also valid for a bunch of other cases & that can make code harder to read - it's the usual reason for using C++ style casts (that can only do a few specific things each) rather than the C style cast which can do many things, sometimes not what you want. Yes, in this case, it'd do the same thing, but when the developer comes back to read the code next week/year/etc or refactors the code (changing the type of the variable), using the least powerful, most legible, mechanism will help them avoid some potential traps.<br><br>Does that make sense?<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">--<br>
"The Direct3D Graphics Pipeline" free book <<a href="http://tinyurl.com/d3d-pipeline" target="_blank">http://tinyurl.com/d3d-pipeline</a>><br>
     The Computer Graphics Museum <<a href="http://ComputerGraphicsMuseum.org" target="_blank">http://ComputerGraphicsMuseum.org</a>><br>
         The Terminals Wiki <<a href="http://terminals.classiccmp.org" target="_blank">http://terminals.classiccmp.org</a>><br>
  Legalize Adulthood! (my blog) <<a href="http://LegalizeAdulthood.wordpress.com" target="_blank">http://LegalizeAdulthood.wordpress.com</a>><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>
</div></div></blockquote></div><br></div></div>