Author: Dann Corbit
Date: 15:01:16 01/17/06
Go up one level in this thread
On January 17, 2006 at 17:50:33, Dan Honeycutt wrote:
>On January 17, 2006 at 14:59:15, Robert Hyatt wrote:
>
>...
>>
>>if (a && b) where if a is 0, b would not even be fetched usually...
>>
>
>I thought, in this case, b _must_ not be fetched.
>
>Best
>Dan H.
3.5: But what about the && and || operators?
I see code like "while((c = getchar()) != EOF && c != '\n')" ...
A: There is a special "short-circuiting" exception for these
operators: the right-hand side is not evaluated if the left-hand
side determines the outcome (i.e. is true for || or false for
&&). Therefore, left-to-right evaluation is guaranteed, as it
also is for the comma operator. Furthermore, all of these
operators (along with ?:) introduce an extra internal sequence
point (see question 3.8).
References: K&R1 Sec. 2.6 p. 38, Secs. A7.11-12 pp. 190-1; K&R2
Sec. 2.6 p. 41, Secs. A7.14-15 pp. 207-8; ISO Sec. 6.3.13,
Sec. 6.3.14, Sec. 6.3.15; H&S Sec. 7.7 pp. 217-8, Sec. 7.8 pp.
218-20, Sec. 7.12.1 p. 229; CT&P Sec. 3.7 pp. 46-7.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.