i got a very strange problem with a variable that has name 'val'. I will try my best to explain it. I cannot make any small code example that do the same issue and my project is very big so can't upload it here also.
The code i try is (part of it)
//the .cpp file
int val = 136;
int val2 = 386;
float valF = 412.f;
void GUI::MyClass::OnRender()
{
MessageBoxW(
0,
std::to_wstring(val).c_str(),
L"Error",
MB_OK
);
}
//in .h file there is only the GUI::MyClass class
the 3 variables can accesed from the source file, are not in any class or in any header.
So for example i do these steps;
- change 'val' to 3456
- built and run with windows debugger
- program show '3456' that is correct as expected...
- close exe
- change 'val' to 345
- built and run with windows debugger again
- now program show again '3456' that is wrong!
Sometimes it show the correct value and other times the previous value after each compiling.
But this is the less strange part as if i click the button 'Rebuilt Solution' and not 'Built Solution' it will always show the correct value, but i don't use precompiled headers.
Also 1 more weird part is if do the same steps with 'val2' or 'valF' and print its values always will show the correct value, even with only simple 'Build Solution'!!!
I'm not sure if i do something wrong or if visual studio has a bug on compiler, so i'm very confused now. Maybe i cannot use the variable with name 'val' in visual studio in some cases? Also i did a restart of visual studio but nothing happend.
I am very confused about this problem but i think it is a visual studio compiler bug...
Here are some details about project/visual studio/c++;
- Visual Studio Community 2022 (64-bit) Version 17.0.4
- Not Using Precompiled Headers
- platform toolset: Visual Studio 2022 (v143)
- c++ languange standard: ISO C++17 Standard (/std:c++17)
- SubSystem: Windows (/SUBSYSTEM:WINDOWS)