Garrett> Actually, I think a few other places I also used != 0.  Although
Garrett> compilers evaluate it the same way, I prefer to make comparison
Garrett> against zero explicit.  I thought at one point I'd even seen a
Garrett> style guide recommending or requiring this.

Peter> Really?  I don't recall anything about that.

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.

-- John

http://blogs.sun.com/jbeck
_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to