First I should specify that I'm using the clang compiler from Visual Studio. When debugging the following simple program, the WinMain function returns the value of the variable when a peculiar condition seems to be met.
#include <windows.h>
int CALLBACK WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int var = 1;
var = var + 5;
}
The above would output in the debugger: The program '[11396] Project1.exe' has exited with code 6 (0x6).
This behavior seems to happen without fail whenever there is a variable name in the right hand expression of the assignment. If I were to modify the last line to assign just a literal such as var = 5
, the output would be a consistent unrelated value every time: The program '[4148] Project1.exe' has exited with code -858993460 (0xcccccccc).
I suspect that this behavior has to do with WinMain, because when I use plain-old main() instead, I get the expected return of 0. Any idea as to what could be the cause of this strange behavior?