James Carlson wrote:

>Garrett D'Amore writes:
>  
>
>>I'm not sure if the Style Guide makes that difference.  I don't know.  
>>Frankly, this is one of my least favorite rules in the guide, because I 
>>happen to think "if (!foo)" is clearer than "if (foo != 0)".  But I 
>>didn't write the guide, or get to vote on it -- but I do assume that I'm 
>>bound to follow it.
>>
>>If I've misinterpreted what it says, I'd be happy to be corrected, 
>>because to *my* eyes, I agree with Peter.
>>    
>>
>
>I think there's general agreement that treating a bitwise flag test as
>a boolean results in nicely readable code, and should be encouraged.
>In fact, I'd go so far as to say that comparing those expressions
>against zero needs to be outlawed.  "== 0" is very hard to read as
>"not set," while "!= 0" has a hint of not-i-ness about it.
>  
>

My take on it is if you do:

if ((foo & X) == 0)

Then it is much less likely for the you to mistakingly do
(and for the compiler to accept):

if ((foo && X) == 0)

vs

if (foo && X)

So while

if (foo & X)

may work and be ok, it's not what I call
"good defensive programming."

Darren

_______________________________________________
driver-discuss mailing list
driver-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/driver-discuss

Reply via email to