Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!ames!oliveb!intelca!mipos3!pinkas
From: pinkas@mipos3.UUCP (Israel Pinkas)
Newsgroups: comp.lang.c
Subject: Re: conditional expression evaluation question
Message-ID: <367@mipos3.UUCP>
Date: Tue, 13-Jan-87 12:22:06 EST
Article-I.D.: mipos3.367
Posted: Tue Jan 13 12:22:06 1987
Date-Received: Wed, 14-Jan-87 05:31:53 EST
References: <207@rebel.UUCP>
Reply-To: pinkas@mipos3.UUCP (Israel Pinkas)
Organization: Intel, Santa Clara, CA
Lines: 37

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;
> ...
>For now, I am using the following ugly code:
>
>	while (cp < end && triples < MINSKIP) {
>		if ((*cp | *(cp+1) | *(cp+2)) == 0) ++triples;
>		else triples = 0;
>		cp += 3;
>	}

Continue to use you ugly code.  C guarantees (at least K&R and H&S do) that
boolean expressions are evaluated only as much as possible, and left to
right.  As such, the first time *cp++ evaluates non-zero, the expression is
guaranteed to result in a non-zero value, and evaluation stops.  (You can
do wierd things like ((expr1 && expr2) || expr3); instead of
if (expr1) then expr2; else expr3; iff expr2 does not return a zero value.)
The first piece of code will actually find the first run of 3 * MINSKIP
consecutive null bytes, not guaranteed to fall on any boundary.  (This
assumes that your compiler is a "true C" compiler.  But that is another
matter.)

-Israel

-- 
----------------------------------------------------------------------
UUCP:	{amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!pinkas
ARPA:	pinkas%mipos3.intel.com@relay.cs.net
CSNET:	pinkas%mipos3.intel.com