문제

Is there a way to tell the Intel compiler to not optimize-away un-used variables? I am trying to time some code and I currently prevent the optimization by using a cout statement on the variables.

Ideally the solution would tell the compiler to not remove the variable via a pragma/hint, otherwise I would have to use a program-wise argument?

도움이 되었습니까?

해결책

Use the volatile keyword when assigning your variable to let the compiler know not to optimize it. As far as I know, this is a C/C++ standard so it should work on any compiler. See the MSDN link for more info.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top