Hello Edmund,
as far as I know function calls (whether inline or not) are sequence points (as defined by the standard) so I wouldn't worry there (plus arguments are guaranteed to be evaluated before function body is entered).
A real-life example that happened to me some time ago:
Code: Select all
nodes[res].index = addNode( n->front );
where nodes is a vector that can be changed by subsequent call to recursive method addNode.
What happened is that the compiler cached pointer to nodes before calling addNode which pushes back some elements (sure I might have preallocated nodes in advance by using pre-traversal).
It's because the order of evaluation of assignment operator is not guaranteed (it's not a sequence point unlike && and || operators which are guaranteed to evaluate left to right),
so the compiler is free to evaluate left side first (read where to store the result, not the store itself).
Fixing it was simple enough:
Code: Select all
int tmp = addNode( n->front );
nodes[res].index = tmp;
One has to be careful sometimes
From what I've read sequence points are also automatically "inserted" at the end of each expression statement.
Hope it helps.