简体   繁体   中英

Unable to watch variable values in Visual studio with compiler optimization set to Maximize speed(/O2)

I am using working on a c++ application in Visual studio 2008 I have built my project with Maximize speed(/o2) (From Properties -> configuration properties -> c/c++ -> optimization -> optimization) Unable to watch the variable values while debugging the code. Pls help.

This is normal. Once you activate optimizations, the compiler pretty much ignores all your variable requests and tries to do what it thinks is best.

There's a reason why the debug builds have no optimizations enabled :)

Edit: You might have some luck with enabling or disabling optimizations for specific bits of code. Try this link: http://msdn.microsoft.com/en-us/library/chh3fb0k(VS.80).aspx

Sometimes resorting to the "disassembly view" of the C++ code and stepping through the optimized release x86 give you an idea of what's going on. Pay special attention to function calls (many times those cannot be optimized out), and code around those calls - before and after, and register usage (many times variables are optimized into hardware registers).

Regardless of whether this works or not, you learn a little bit about x86 assembly, compiler optimization, and how C++ is actually implemented!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM