Peter Memishian wrote:
>  > It ("C Style and Coding Standards for SunOS") says in section 19:
>  > 
>  >    Do not default the boolean test for nonzero, i.e.
>  >           if (f() != FAIL)
>  >    is better than
>  >           if (f())
>  > 
>  > then:
>  > 
>  >    Never use the boolean negation operator (!) with non-boolean
>  >    expressions. In particular, never use it to test for a NULL
>  >    pointer or to test for success of the strcmp function, e.g.,
>  > 
>  >           char *p;
>  >           ...
>  >           if (!p)                  /* WRONG */
>  >                    return;
>  >           if (!strcmp(*argv, "-a"))        /* WRONG */
>  >                    aflag++;
>  > 
>  > I'm guessing that's what Garrett was thinking of.
>
> I don't think that applies to testing flag values.  I see a significant
> difference between "if (foo())" and "if (foo->bar & MYFLAG)".
>   

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.

    -- Garrett


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

Reply via email to