1

I am compiling flops via a loop with simple operations like such:

for (i = beginvar; i < endvar; i++) {
    for (j = beginvar; j < endvar; j++) {   
        num1 = ((num1 + num2) / num1);
    }
}

I never do anything with num1, however, and so the compiler is skipping over it and this loop takes 0 ms no matter how large beginvar and endvar are.

My question is, how can I force the compiler to execute the nested loop?

I've tried declaring num1 as volatile, but this does fewer optimizations than I want. I want the compiler to optimize, but I want it to execute this loop as well.

I also would not like to print anything to the terminal

4

1 に答える 1

1

Use the value of num1 after the loop for something, so that the compiler cannot trivially eliminate it.

于 2012-11-30T18:51:22.777 に答える