Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!lll-lcc!seismo!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.lang.c Subject: Re: short circuit evaluation Message-ID: <5199@mimsy.UUCP> Date: Sun, 25-Jan-87 21:17:54 EST Article-I.D.: mimsy.5199 Posted: Sun Jan 25 21:17:54 1987 Date-Received: Tue, 27-Jan-87 02:30:59 EST References: <425@bobkat.UUCP> <102600001@datacube> <34@umich.UUCP> <14479@amdcad.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 In article <14479@amdcad.UUCP> tim@amdcad.UUCP (Tim Olson) writes: >What about if either the left side expression or the right side >expression [of an otherwise short-circuitable expression] contained >a side-effect (or a procedure call, which also may have a side- >effect)? These cannot be short-circuited when bit-wise operators >are used. c = *p++ & *q++; /* are both p and q always incremented? */ I can find no promise in K&R that bitwise expressions are not short circuited even in the presence of side effects. The ANSI draft may have more to say. In any case, I would advise not counting on full evaluation. It is even conceivable that a compiler might generate if ((c = *p) != 0) c &= *q; p++; q++; which, if p and q point to device registers, is not the same! In general, existing C compilers will not attempt to optimise away the AND above if *p++ (or *q++) is zero, simply because the `C philosophy' is that if you *meant* c = *p++ ? p[-1] & *q++ : 0; you would have written that. But is it mandated? I cannot say. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu