Why #pragma optimize("", off)

Stokke picture Stokke · Mar 13, 2015 · Viewed 28.5k times · Source

I'm reviewing a C++ MFC project. At the beginning of some of the files there is this line:

#pragma optimize("", off)

I get that this turns optimization off for all following functions. But what would the motivation typically be for doing so?

Answer

Ray picture Ray · Jan 23, 2016

I have used this exclusively to get better debug information in a particular set of code with the rest of the application is compiled with the optimization on. This is very useful when running with a full debug build is impossible due to the performance requirement of your application.