Does the following code invoke UB ?
int main(){
volatile int i = 0;
volatile int* p = &i;
int j = ++i * *p;
}
Does the following code invoke UB ?
int main(){
volatile int i = 0;
volatile int* p = &i;
int j = ++i * *p;
}
Yes that is Undefined Behavior because you are trying to violate the second rule..
The Standard states that
1) Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression.
2) Furthermore, the prior value shall be accessed only to determine the value to be stored.
Note: The order of evaluation of the operands of *
operator is unspecified and *p
is nothing but i
.