Order of evaluation

In standard C++ (and C) must

  1. All of a functions arguments be full evaluated before the function is called.
  2. No function calls may interleave with one another, a prior function call must be fully done before the next can start.
  3. Expressions used as function arguments can be evaluated in any order, also interleaved(!) unless this is prohibited by rule 1 or 2.

This means that in the expression

then expression1 and expression2 must be evaluated before func is called, but we don’t know which of them is evaluated first.

In the more complicated example of

then we know that

  1. expression1 is evaluated before g
  2. expression2 is evaluated before h
  3. both g() and h() are evaluated before f() is called.

However, we don’t know if

  • expression1 or expression2 is evaluated first
  • g() or h() is evaluated first
  • expression1 is fully evaluated before h() is called (!)