BOOLEAN as enum

Sean Fagan seanf at sco.COM
Thu Apr 12 00:05:01 AEST 1990


In article <986 at mti.mti.com> adrian at mti.UUCP (Adrian McCarthy) writes:
>  if (!strcmp(s1,s2))  /* YUCK!!! */

Why "YUCK!!!"?  This is perfectly reasonable code, with wide-spread usage.
To me, it's now more readable than "if (strcmp (s1, s2) == 0)", although I
will admit I'm a bit weird.

>what the function does and didn't mistake for a boolean function.

Oh.  I see.  You simply don't understand C.  Now I understand your post.

>Assuming:  f1 = fopen("data.dat","r"); test like this:
>
>  if (f1 = NULL) { /* handle error */ }
>not like this:
>  if (!f1) { /* handle error */ }

Of course not; these mean two different things.

>Similary: if (count > 0) {}, not: if (count) {}.

These are only equal if count is unsigned, unless the programmer *knows*
that count will never be negative.

-- 
-----------------+
Sean Eric Fagan  | "It's a pity the universe doesn't use [a] segmented 
seanf at sco.COM    |  architecture with a protected mode."
uunet!sco!seanf  |         -- Rich Cook, _Wizard's Bane_
(408) 458-1422   | Any opinions expressed are my own, not my employers'.



More information about the Comp.lang.c mailing list