I’m viewing variables using the debugger. In debug builds everything in the code below appears as I expect it to, but when I switch to release builds I’m getting strange results. Why?
#include <iostream>
void say_hello(int argc, char* argv[])//In release mode argc has different values from 124353625 to 36369852 when viewed in the debugger
{
std::cout << "In say_hello()\n";
}
int main(int argc, char* argv[])
{
say_hello(3,argv);//when instead of literal I enter "argc" everything is ok.
return 0;
}
Thanks for help.
Since you’re not using those parameters in your program, you must be trying to observe their values in the debugger. But, again since you’re not using them in your program, the compiler is free to do whatever it wants with their values. It may remove them entirely, leaving the debugger with nothing but gibberish to display when you ask for each parameter’s value. If you change your optimization and debug-information settings, you may see different results.