Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!sunic!news.funet.fi!hydra!cc.helsinki.fi!wirzenius From: wirzenius@cc.helsinki.fi (Lars Wirzenius) Newsgroups: comp.lang.c Subject: Re: Efficient STRing CoMPares? Message-ID: <1991Mar19.123218.5597@cc.helsinki.fi> Date: 19 Mar 91 12:32:18 GMT References: <1991Mar15.142821@mars.mpr.ca> <15486@smoke.brl.mil> <1193@caslon.cs.arizona.edu> <15496@smoke.brl.mil> <1991Mar18.174207.7377@bingvaxu.cc.binghamton.edu> Organization: University of Helsinki Lines: 33 In article <1991Mar18.174207.7377@bingvaxu.cc.binghamton.edu>, consp06@bingsuns.cc.binghamton.edu (Robert Konigsberg) writes: > Somebody said part of the problem with string comparisons is that if > the most of the strings are equivelant, there will be alot of > processor time. Wouldn't it be good then, to include in the macro, > something to compare the actual POINTERS? If the pointers are the > same then the two strings have no CHOICE but to be equivelant. This > would really cut down the time under certain situations. No, two strings may be equivalent, even if they are stored in different places (this applies to string constants too, if they appear several times). For example: char *s = "hello"; char *t = "hello"; s and t may or may not point to the same character, you can't depend on either behaviour. Another example: char s[10] = "hello"; char t[10]; strcpy(t, s); Now the contents (up to and including the terminating '\0', but no longer of course) of s and t are the same, but the addresses of the two variables are different. Of course, if two pointers to char are equivalent, the strings will be the same, but this isn't the only occurence, nor do I think it is all that common. -- Lars Wirzenius wirzenius@cc.helsinki.fi