Is there any reason that the compiler cannot optimize the following 2 statements out in main even I turned on fully optimization in Visual C++? Any side effect to access a int variable in memory?
int _tmain(int argc, _TCHAR* argv[])
{
volatile int pleaseOptimizeMeOut = 100;
(pleaseOptimizeMeOut);
return 0;
}
It can’t optimise them out because you have declared the variable to be
volatile. Loads and stores tovolatilequalified objects are part of the “externally visible” effects of the C abstract machine.(By the way, there are plenty of side effects when accessing a variable in memory; it can update hardware memory caches including the TLB, and possibly also cause page faults. And the memory your process is executing in might be being snooped on by another process, like a debugger).