I understand that this behavior is undefined:
int i = 0; int a[4]; a[i] = i++;
since the evaluation order of i for the left and right sides is undefined ( ; is the only point in the sequence).
Taking this argument further, it seems to me that it will be undefined undefined behavior:
int i = 0; int foo(){ return i++; } int main(){ int a[4]; a[i] = foo(); return 0; }
Despite the fact that on the right side of = there are several points in the sequence, as I understand it, there are still undefined it is not indicated whether f() or a[i] is evaluated first.
Are my assumptions correct? Should I take painstaking care when I use a global or static variable on the left side of the task, which the right hand does not modify under any circumstances?
c ++ sequence-points
odinthenerd
source share