When you create Release, the compiler performs many optimizations in your code. Many of the optimizations include replacing variables with hard-coded values ββwhen possible and correctly done. For example, if you have something like:
int n = 42; cout << "The answer is: " << n;
By the time the optimizer is done with this, it will often look bigger:
cout << "The answer is: " << 42;
... and the variable n completely excluded from your program. If you are releasing a version of this program and trying to check the value of n , you may see very odd values ββor the debugger may report that n does not exist at all.
There are many other optimizations that make debugging an optimized program difficult. Placing a breakpoint after initializing an array can lead to very misleading information if the array was deleted, or if its initialization was moved to another location.
Another common optimization is to exclude unused variables, for example:
int a = ma[0];
If your program does not have code that actually uses a , the compiler will see that a not required, and optimize it so that it no longer exists.
To see the values ββthat were initialized with ma , the simplest somewhat reliable approach is to use the so-called sprintf debugging:
cout << "ma values: "; copy (ma, ma+4, ostream_iterator <int> (cout, ", "));
And look what really is.
source share