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.
Actually, what I tend to like better, although it's redundant, is if ((flags & MYFLAG) == MYFLAG) at least partially because when, inevitably, I have to test two flags, and want them both to be true, it's easier to extend to that case: if ((flags & (MYFLAG1 | MYFLAG2)) == (MYFLAG1 | MYFLAG2)) It also makes the point subconsciously that it's a bit value I'm looking at, not a boolean. But I'm certainly not really offended by the comparison-less test. _______________________________________________ driver-discuss mailing list driver-discuss@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/driver-discuss