Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!cmcl2!brl-adm!adm!Alan_Cote.DlosLV-Comm@Xerox.COM From: Alan_Cote.DlosLV-Comm@Xerox.COM Newsgroups: comp.lang.c Subject: Re: Message-ID: <8011@brl-adm.ARPA> Date: Wed, 24-Jun-87 18:26:19 EDT Article-I.D.: brl-adm.8011 Posted: Wed Jun 24 18:26:19 1987 Date-Received: Fri, 26-Jun-87 06:00:49 EDT Sender: news@brl-adm.ARPA Lines: 27 PEBRBV writes, >Henry Spencer suggests (assuming a and b have >no side effects) >>#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) >>This makes a considerable speed difference in programs that use strings >>a lot, since string comparisons usually fail on the very first character. >Except that the compiler is free to do the strcmp call before the >comparison *(a)==*(b), or even do both tests and AND the results. >But a good optimizer should do it efficiently. Kernighan and Ritchie specifies (Appendix A, clause 7.11), "Unlike &, && guarantees left-to-right evaluation; moreover, the second operand is not evaluated if the first operand is 0." Therefore, the compiler is NOT free to do both tests! However, STREQ may have only minimal value, as any good strcmp() implementation will return immediately upon discovering that the first bytes of its arguments do not match. - Alan T. Cote'