Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top