Path: utzoo!yunexus!ists!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: compare strings, strcmp Keywords: strcmp,strings Message-ID: <7035@ficc.uu.net> Date: 17 Nov 89 17:37:53 GMT Article-I.D.: ficc.7035 References: <4463@blake.acs.washington.edu> <11605@smoke.BRL.MIL> <308@charyb.COM> <5205@mentor.cc.purdue.edu> Reply-To: peter@ficc.uu.net (Peter da Silva) Organization: Xenix Support, FICC Lines: 18 > >>#define StrEq( a, b ) (*(a) == *(b) && strcmp( a, b ) == 0) /* UNSAFE */ > > Why the UNSAFE comment? This looks like utterly standard C to me... Because !a! and !b! may be evaluated multiple times. What if you do something like !StrEq(*++argv, "poodle-hair");!? If !*++argv=='p'!, then it will evaluate !++argv! again. > #define StrEq(a,b) ((*(a) == *(b))?strcmp(a,b):*(a)-*(b)) This has the advantage that it will return the same result as strcmp, but is otherwise as unsafe (albeit a little more predictable, since it will always evaluate both arguments twice). -- `-_-' Peter da Silva . 'U` -------------- +1 713 274 5180. "vi is bad because it didn't work after I put jelly in my keyboard." -- Jeffrey W Percival (jwp@larry.sal.wisc.edu)