operator evaluation question

L

linq936

Hi,
I see the following description in <<Expert C Programming>>,

the order is defined for && and || and a couple of other operators.
These 2 evaluate their operands in a strict left-to-right oder,
stopping when the result is known.

Is this really true? I think the order is compiler dependent.

Thanks.
 
R

Richard Heathfield

(e-mail address removed) said:
Hi,
I see the following description in <<Expert C Programming>>,

the order is defined for && and || and a couple of other operators.
These 2 evaluate their operands in a strict left-to-right oder,
stopping when the result is known.

Is this really true? I think the order is compiler dependent.

The Standard mandates the order and the short-cut evaluation.
Implementations have no leeway in this regard.
 
C

Chris Dollin

Hi,
I see the following description in <<Expert C Programming>>,

the order is defined for && and || and a couple of other operators.
These 2 evaluate their operands in a strict left-to-right oder,
stopping when the result is known.

Is this really true? I think the order is compiler dependent.

Not for && and || and ?: and the comma-operator it isn't.
 
J

Joe Wright

Hi,
I see the following description in <<Expert C Programming>>,

the order is defined for && and || and a couple of other operators.
These 2 evaluate their operands in a strict left-to-right oder,
stopping when the result is known.

Is this really true? I think the order is compiler dependent.

Thanks.
Perhaps confusing order and precedence. The language specifies the
precedence of operators; c = a + b for example. + has higher precedence
than = and so (a+b) will be evaluated before the assignment to c.

Order of evaluation is a different issue. Given x = f() + g() makes no
guarantee that f() is evaluated before g(). Compiler decides.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top