The order in which function parameters are evaluated is unspecified behavior in the C language. Both outputs are correct because it is how the particular compiler decided to implement it. Your program is "wrong" since it does not correctly deal with this unspecified behavior by using intermediate values to guarantee an order.
This program yields the same result (3 3 4 4 5 5
) with both compilers
#include <stdio.h>
int main() {
int x = 1;
int y = x;
x = x + 2;
printf("%d %d %d ", x, x, (y << 2));
int value1 = x++;
int value2 = ++value1;
int value3 = ++value2;
printf("%d %d %d \n", value1, value2, value3);
return 0;
}
Clang actually provides a helpful warning by default to avoid this:
warning: unsequenced modification and access to 'x' [-Wunsequenced]
printf("%d %d %d ", x, (x = x + 2), (x << 2));
~ ^