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. (Whether we ought to have bitwise values at all or should be using explicit booleans is probably a separate matter, and doesn't matter much given the context here.) What the Style Guide is trying to prevent is the use of weird non-boolean values as though they were boolean. This is fairly ugly, because it just doesn't read right out loud: if (foo = malloc(10)) { /* looks like I can allocate 10 more bytes! */ } If foo is ... what? This is much worse: if (open("/dev/null", O_RDWR)) { /* now why is stdin already open? */ } The code needs to be readable. -- James Carlson, Solaris Networking <[EMAIL PROTECTED]> Sun Microsystems / 35 Network Drive 71.232W Vox +1 781 442 2084 MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677 _______________________________________________ driver-discuss mailing list driver-discuss@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/driver-discuss