Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcnc!gatech!akgua!rebel!george From: george@rebel.UUCP (George M. Sipe) Newsgroups: comp.lang.c Subject: conditional expression evaluation question Message-ID: <207@rebel.UUCP> Date: Mon, 12-Jan-87 16:40:40 EST Article-I.D.: rebel.207 Posted: Mon Jan 12 16:40:40 1987 Date-Received: Tue, 13-Jan-87 02:36:54 EST Reply-To: george@rebel.UUCP (George M. Sipe) Organization: Tolerant Systems, Atlanta GA Lines: 27 Summary: are all subexpressions evaluated? References: 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?". In my example, if the first byte is non-null, then the result is known to be false and there is no need to evaluate the remaining subexpressions. However, I am counting on the whole expression being evaluated. Assuming that C does guarantee full execution of the conditional test, would I be taking a significant chance that an optimizing compiler might be too tricky and (incorrectly) fail to do the full evaluation? 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; }