I am wondering how to turn off optimization for the following loop. I have searched and tried some flag but not working. Thanks.
#include <iostream>
int fun(int i) {return ++i;};
int main ()
{
int res = 0;
for (long i = 0; i < 10000; i++)
{
res += fun(i);
}
std::cout << res;
}
-O1 will remove the loop and directly hard code the result. I would like to use -O3 but with this optimization turned off.