order of operations

P

pauldepstein

Assuming variables and functions have been defined correctly and x is
an int, is it unambiguous to write

x = f(x) + g(x);

Or does this lead to the possibility that the compiler will do x =
f(x) and then substitute that f(x) value into g(x)?

Thanks,

Paul Epstein
 
K

kwikius

Alf P. Steinbach said:
* (e-mail address removed):

It's unambigious if neither function has side-effects.

However, if there are side-effects, then it becomes relevant that the
order of evaluation is unspecified.

What happens if both f(x) and g(x) are executed in parallel? Is that allowed
by the C++ standard?

regards
Andy Little
 
J

James Kanze

What happens if both f(x) and g(x) are executed in parallel?
Is that allowed by the C++ standard?

Only if the compiler can determine that it doesn't matter. A
function call is a sequence point, and you can't continue with
the rest of the calling expression (including, in this case,
calling g(x)) until the function returns. Modulo the "as if"
rule.
 

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,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top