Reputation: 18171
I found strange Visual Studio 2010
behavior while debugging project. Variable string s
was initialized with ""
, but debugger shows garbage. Debug point is in the second line of s
initialization.
if I do cout<<s
, it prints normal value - not garbage.
One more immage to be shure where is breakpoint
In other project places debugger works fine. Procedure where I have garbage is win message handler. Message was transmitted from same project other thread.
LRESULT CMainWindow::OnMessageAuthorise(WPARAM wParam, LPARAM lParam)
{
string s= "";
...
}
What is wron?
UPD: Problem is in profile Debug/Release selection. If I choose Release I have these garbage on variables. Why it is so?
Upvotes: 0
Views: 579
Reputation: 16147
Short answer: unless you're willing to inspect disassembly, you can't set watches in release builds. That's what debug builds are for.
Longer answer: In release builds many optimizations can make the mapping of a variable name to a memory address much harder. The simplest case - the variable might have no memory address: it can be saved only in registers. Traditional generation of PDB files (the files that hold - among others - this mapping info) didn't even try to cope with the difficulties emanating from optimizations, but since VS2012 a new switch takes a substantial step in that direction.
Upvotes: 1