Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!rlgvax!scc From: scc@rlgvax.Reston.ICL.COM (Stephen Carlson) Subject: Re: One more point regarding = and == (more flamage) Reply-To: scc@rlgvax.OPCR.ICL.COM (Stephen Carlson) Organization: International Computers Limited Date: Wed, 27 Mar 91 17:39:49 GMT Message-ID: <1991Mar27.173949.25016@rlgvax.Reston.ICL.COM> References: <925@isgtec.UUCP> <1991Mar26.180311.29125@rlgvax.Reston.ICL.COM> <7318:Mar2622:58:0391@kramden.acf.nyu.edu> In article <7318:Mar2622:58:0391@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >In article <1991Mar26.180311.29125@rlgvax.Reston.ICL.COM> scc@rlgvax.OPCR.ICL.COM (Stephen Carlson) writes: >> while (*s++ == *t++) >> ; >> is not well set up to compare two arrays. > >Actually, sentinels are among the fastest ways to do a linear search >without wasting noticeable extra space. If you had quoted the entire context, you would have read: | while (*s++ == *t++) | ; | | is not well set up to compare two arrays. It does not check for a zero | termination. It is really only useful when the programmer has already | set up guaranteed unequal sentinals at the end of the array. Then the | pointers after the loop are one greater than would be useful. My point was that that particular encoding is not well set up even for sentinel searches. The post-loop pointers need to be readjusted. This code, for example, does not suffer that disadvantage: while (*s == *t) s++, t++; After the loop, the pointers are pointing at the unequal elements, not one past the unequal elements--which may even end up past the array bounds! Your general point about sentinels is correct, of course. -- Stephen Carlson | ICL OFFICEPOWER Center | In theory, theory and scc@rlgvax.reston.icl.com | 11490 Commerce Park Drive | practice are the same. ..!uunet!rlgvax!scc | Reston, VA 22091 |