So I have a following snippet (and a good reason behind it):
#include <iostream>
volatile const float A = 10;
int main() {
volatile const float* ptr = &A;
float* safePtr = const_cast<float*>(ptr);
*safePtr = 20;
std::cout << A << std::endl;
return 0;
}
Under G++ v8.2.0 (from MinGW suite), this program compiles fine and outputs 20
as expected. Under VS2019, it compiles, but throws a runtime exception - Exception thrown at 0x00007FF7AB961478 in Sandbox.exe: 0xC0000005: Access violation writing location 0x00007FF7AB969C58
.
Is there a way to make VS2019 behave the same way the G++ does? And how to do it with CMake?