Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: comp.lang.c Subject: Re: conditional expression evaluation question Message-ID: <3950@utcsri.UUCP> Date: Mon, 19-Jan-87 13:52:55 EST Article-I.D.: utcsri.3950 Posted: Mon Jan 19 13:52:55 1987 Date-Received: Mon, 19-Jan-87 19:21:05 EST References: <207@rebel.UUCP> <603@rtech.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 40 Summary: In article <207@rebel.UUCP> george@rebel.UUCP (George M. Sipe) writes: >I need to check a string, composed of byte triples, for a null area no >less than MINSKIP triples in length. A pointer, cp, is initialized to >a triplet boundary. After the test, it must remain on a triplet >boundary. Initially, I wrote the following: > > while (cp < end && triples < MINSKIP) > if ((*cp++ | *cp++ | *cp++) == 0) ++triples; > else triples = 0; > > ... [problems with above] ... Many have pointed out that the test clause should be something like cp[0] == 0 && cp[1] == 0 && cp[2] == 0 and the increment should be done separately with cp += 3 or cp = &cp[3]. Here's a solution using a pointer to an array. ( Watch carefully. At no time do my fingers leave the keyboard...): typedef char triple[3]; triple *tp,*end; /* or char (*tp)[3], (*end)[3]; */ ... while( tp < end && triples < MINSKIP ){ if( (*tp)[0] == 0 && (*tp)[1] == 0 && (*tp)[2] == 0 ) ++triples; else triples = 0; ++tp; /* next triple */ } Note that (*tp)[1] should give the same code as cp[1], and ++tp should be the same as cp += 3, so the difference is merely semantic, and the question is whether you feel that the above makes more sense than the cp solution. If a lot of things are done with these triples, it can end up being somewhat cleaner, since a lot of '3' constants become implicit in the addressing. -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...