On 3/14/06, <b class="gmail_sendername">Rob Landley</b> &lt;<a href="mailto:rob@landley.net">rob@landley.net</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Monday 13 March 2006 1:54 pm, Robin Farine wrote:<br>&gt; On Sunday March 12 2006 06:24, Rob Landley wrote:<br>&gt; &gt; If one of them is a constant, it emits no warning.<br>&gt;<br>&gt; Indeed. I could not reproduce any gcc warning with 'if (a &amp; b)', 'a'
<br>&gt; and 'b' being constants or variables. Must be due to a mistake<br>&gt; while picking mushrooms.<br><br>It might have produced a warning on older versions.<br><br>if (a &amp; b) doesn't work quite like if (a &amp;&amp; b), but it's not the obvious error
<br>that if (a = b) tends to be.&nbsp;&nbsp;If you restrict yourself to logic values rather<br>than arbitrary numbers, and don't mind losing the short circuit behavior,<br>then something if (a==b &amp; c==d) will in fact work as expected.
</blockquote><div><br>(Rob gets two copies, reply/reply-all typo that compilers don't catch)<br><br>In large projects that actually use code-inspection, and hunt/kill warnings,&nbsp; double-parenthesis<br><br>&nbsp;&nbsp;&nbsp; if (( a = b )) ...
<br><br>... and LHS constants:<br><br>&nbsp;&nbsp;&nbsp; if (NULL == (fd = open (... )) )
<br><br>... tend to show &quot;yeah, I meant that when I wrote that, it's
not a coding typo&quot; even if they don't add obvious readability.&nbsp; In
addition (double-parens) to quieting the warning, or (NULL == x) using
the compiler to avoid (a = 0) errors, this coding style lets us skim
quickly to things we need to question.
<br><br>..so it's not a bad habit, BB or otherwise :)<br><br>Allan&nbsp;</div></div>