The procedure for evaluating expressions in C

If I have the following expression:

c = (a) * (b)

What does the C90 standard say about evaluating the subexpression order “a” and “b”?

+5
source share
2 answers

There is no specified order, since the multiplication operator is not a sequence point. Sequence points include a comma operator, the end of a complete expression, and function calls. Thus, the order of evaluation (a)and (b)implementation dependent compiler. Therefore, you should not try to do something in (a)that will have a side effect that you want to see in (b)to create the correct result.

For instance:

int a=5;
int b = (a++) * (a++); //<== Don't do this!!

C, .

+11

* C90.

C90 ( C90):

(C90, 6.3) " , , ( -(), &, ||,?: comma-). , , "

*, , :

c =  f() * g();

f() g():

a = f();
b = g();
c = a * b;

a = g();
b = f();
c = a * b;

.

+3

All Articles