Path: utzoo!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uwm.edu!lll-winken!taco!mcnc!duke!drh From: drh@duke.cs.duke.edu (D. Richard Hipp) Newsgroups: comp.lang.c Subject: Re: Efficient STRing CoMPares? Message-ID: <669305557@juliet.cs.duke.edu> Date: 18 Mar 91 14:12:38 GMT References: <1991Mar15.142821@mars.mpr.ca> <15486@smoke.brl.mil> Organization: Duke University Computer Science Dept.; Durham, N.C. Lines: 14 In article <15486@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <1991Mar15.142821@mars.mpr.ca> stone@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.