This code I was benchmarking and noticed it would not stop running when optimizations were turned on, im using Code Blocks with MinGW 4.7.0.
If I change the iterator to unsigned i;
the loop will end with optimizations on. Otherwise I need to turn off optimizations to use the int i;
declaration.
int main(void)
{
int i;
int a, b;
a = 5; b = 24;
for(i = 0; i < 2700000000; i++)
asm_swap(&a, &b);
return 0;
}
There is also a warning: this decimal constant is unsigned only in ISO C90 [enabled by default]
apparently referring to the 2.7 billion constant. I do not think this would change anything as either int
or unsigned
can carry this value, which is part of why I am so confused here. I have no explanation.
What is the issue with having the int
type and optimizations enabled?