Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!clyde!cbatt!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!k.cc.purdue.edu!ag0 From: ag0@k.cc.purdue.edu (Colin Jenkins) Newsgroups: comp.lang.c Subject: Re: conditional expression evaluation question Message-ID: <1686@k.cc.purdue.edu> Date: Wed, 14-Jan-87 14:23:37 EST Article-I.D.: k.1686 Posted: Wed Jan 14 14:23:37 1987 Date-Received: Thu, 15-Jan-87 22:06:43 EST References: <207@rebel.UUCP> Reply-To: ag0@k.cc.purdue.edu.UUCP (Colin Jenkins) Organization: Purdue University Computing Center Lines: 30 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; > >After looking at it, I wasn't absolutely sure that it would perform as >expected. My question is "Does C guarantee execution of portions of a >conditional expression, even when the result is known after partial >evaluation?". Actually, you have only one conditional expression in your if statement. The "|" is a bitwise or and not a logical connective. If that is what you intended then you don't have to worry since you have only one conditional expression. The answer to you question about evaluation is no however. From page 38 of K&R "The C Programming Language": "Expressions connected by the && or || are evaluated left to right, and evaluation stops as soon as the truth or falsehood of the result is known." Colin