more on TRUE and FALSE (side-comment)
Brad Appleton
brad at SSD.CSD.HARRIS.COM
Mon Sep 17 23:44:57 AEST 1990
In article <quan.653570879 at sol> quan at sol.surv.utas.oz (Stephen Quan) writes:
>Personally I hate 'writing' programs with :
>
> if (strcmp(name,"hippo")==0) ....
>
>I know 'strcmp(a,b)' is designed to return 3 types of value :
>-ve : a comes before b.
> 0 : a equals b.
>+ve : a comes after b.
>
>but it drives me balmy (not completely balmy though!) all the same.
>
>Anyone got a cure? At the moment I'm trying DIET COKE!
It may not be terribly readable, but i use:
if ( !strcmp(s1, s2) ) { ... }
To test for equality!!
Ive also seen (but dont use) the following:
#define strEQ(s1,s2) !strcmp(s1,s2)
#define strNE(s1,s2) strcmp(s1,s2)
#define strLT(s1,s2) ( strcmp(s1,s2) < 0 )
#define strGT(s1,s2) ( strcmp(s1,s2) > 0 )
(and similar stuff for strncmp too!)
______________________ "And miles to go before I sleep." ______________________
Brad Appleton brad at travis.ssd.csd.harris.com Harris Computer Systems
...!uunet!hcx1!brad Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list