Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: Style question re common C expression. Message-ID: <8164@utzoo.UUCP> Date: Thu, 18-Jun-87 12:32:17 EDT Article-I.D.: utzoo.8164 Posted: Thu Jun 18 12:32:17 1987 Date-Received: Thu, 18-Jun-87 12:32:17 EDT References: <4934@utcsri.UUCP> Organization: U of Toronto Zoology Keywords: STREQ Lines: 17 > ... like the standard "#define STREQ(s,t)(strcmp(s,t) == 0)"? This is slightly off the topic, but note two things: First, that should be "(strcmp((s),(t)) == 0)" for safety's sake, although in this case trouble is unlikely. Second, if you don't indulge in the perversion of routinely using side effects within expressions, then a still better form is: #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. -- "There is only one spacefaring Henry Spencer @ U of Toronto Zoology nation on Earth today, comrade." {allegra,ihnp4,decvax,pyramid}!utzoo!henry