I came across with the following issue On Apple LLVM compiler 3.1:
int numIndex = 0;
int *indices = (int *)malloc(3 * sizeof(int));
indices[numIndex] = numIndex++;
indices[numIndex] = numIndex++;
indices[numIndex] = numIndex++;
for (int i = 0; i < 3; i++) {
NSLog(@"%d", indices[i]);
}
Output: 1 0 1
And
int numIndex = 0;
int indices[3];
indices[numIndex] = numIndex++;
indices[numIndex] = numIndex++;
indices[numIndex] = numIndex++;
for (int i = 0; i < 3; i++) {
NSLog(@"%d", indices[i]);
}
Output: 0 0 1
I'm expecting 0 1 2 as output. The same code using LLVM GCC 4.2 produces the right output. It's there any optimization flags that I'm missing or something I'm misunderstanding?