🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2398

Explaining precedence vs. sequence

#2398
From: Bob Calbridge
Date: Wed, 27 Mar 1996 00:57
37 lines
2278 bytes
I'm currently taking a C++ class in order to teach it next Fall.
I've taught C programming for the last three years so I know a bit
more than some of the people who program in it that they bring in to
teach it.   The class I'm in got into a discussion that I, as a fellow
"student" had a hard time explaining to the class.

The issue revolves around an if statement with a predicate that may
look like the following:

    if (value || ( GetState (value) && dumb == !smart)) {.....

The instructor agrees with me, as I'm sure everyone else here would,
that if value evaluates to true the function GetState() will never
execute due to short circuiting of the logical operators.  A few
people in the class pointed out that the parenthetical nature of the
expression on the right of the || should force it to be evaluated
first.  I know that the standard says that logical operators guarantee
that the evaluation must be performed left to right and stops when the
expression reaches a guaranteed true or a guaranteed false.  I'm not
positive on this, but I suspect that a logical operator imposes a
sequence point that forces the evaluation of the left side.  (Please
confirm if this is true.)  

I wrote a short program to prove this and the instructor demoed it in
class.  Unfortunately, I don't believe the instructor is familiar with
sequence points, though he is aware of their consequences, and has had
a hard time explaining it to the class.  ITMT, some class members are
losing confidence in the book and its author.  Truth to tell, this is
the first time I've been inclined to write to an author and get him
straight on some issue.  This one tends to over simplify and backs up
some loose conceptions with bad examples.

AAR, can someone quote chapter and verse on what covers this
situation?  Any better explanation?

TIA,
Bob
Technical Details
Message-ID: <4ja3pu$p8r@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: bcalbridge@dcccd.edu (Bob Calbridge)
Newsgroups: comp.lang.c.moderated
Subject: Explaining precedence vs. sequence
Date: 26 Mar 1996 18:57:34 -0600
Organization: D C C C D
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4ja3pu$p8r@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: Forte Free Agent 1.0.82