There are several interesting questions raised here regarding undefined behaviour in C. One of them is (slightly modified)
Does the following piece of code result in undefined behaviour?
int i = 0, *a = &i; // Line 1 a[i] = i + 1; // Line 2
Since there is no concrete answer to this part of the question there, and I am interested in knowing the behaviour in C++, I am raising it again here.
Rule #2 from Undefined Behavior and Sequence Points says
Furthermore, the prior value shall be accessed only to determine the value to be stored
Clearly in the example above, the value is being accessed twice: a[i]
(lhs) and i
(rhs), and only one of them (the rhs) determines the value to be stored.
Does Line 2 violate the rule above and result in undefined behaviour in C++03?
There is some confusion as to whether i
is modified at Line 2?