Efficient STRing CoMPares?

D. Richard Hipp drh at duke.cs.duke.edu
Tue Mar 19 00:12:38 AEST 1991


In article <15486 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1991Mar15.142821 at mars.mpr.ca> stone at mars.mpr.ca (Darren Stone) writes:
>>Does anyone know if there's a better (!?) way to compare
>>strings than with strcmp()?
>>I'm looking for any speed advantage I can get!
>
>#define	StrEq( a, b )	(*(a) == *(b) && strcmp( a, b ) == 0)	/* UNSAFE */

StrEq does not duplicate the semantics of strcmp.  Recall that strcmp
returns either negative, zero, or positive depending on whether "a" is
less than, equal to, or greater than "b".  StrEq, on the other hand,
returns only true or false depending on whether or not "a" is
equal to "b".  This will make a big difference if you are using StrEq
to sort, or to do a binary search.



More information about the Comp.lang.c mailing list