I've greatly simplified this question as the same problem arises in a simpler case:
#include <iostream>
int height;
int main()
{
std::cout << height; // Visual Studio debugger shows this value as -858993460
int height;
}
Seems a problem with the debugger displaying the wrong variable value. The variable value is correct, as printing the variable shows the correct global height value, 0.
You are correct, the global variable height
is not shadowed until the declaration of the automatic variable height
in the final statement of main()
.
std::cout << height;
will use the global variable height
.
Yes, this is confusing the debugger. It's displaying the value of the local height
variable, which in a debug build is initialized to 0xCCCCCCCC
, or the -858993460
displayed in decimal mode.
The compiler does the correct thing and fetches the global variable height
in the first line of the function, it's just the debugger that is confused.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With