In C ++ 03, Standard Observed Behavior (1.9 / 6) involves reading and writing volatile data. Now I have this code:
int main() { const volatile int value = 0; if( value ) { } return 0; }
which formally initializes the volatile variable and then reads it. Visual C ++ 10 emits machine code that makes a place on the stack by pushing the word dword there, then writes zero to that place on the stack, then reads that location.
This does not make sense to me - no other code or hardware can know where the local variable is (since it is in automatic storage), and therefore it is unreasonable to expect that the variable could be read / written by any other side and therefore it can be eliminate in this case.
? , ?
, ( , , ).
, , MSVC , . , volatile , , " ". . , MSVC volatile.
volatile
, , , , "", - , . , , : , , .
, , ? .
, volatile: , , .
volatile const, , . , , .
const
Volatile .
volatile int x; spawn_thread(&x); x = 0; while (x == 0){};
, x .
x
const. , , .
- , ( )
? , x86 , ?
, .
( !), - . volatile , .
. ,
. volatile V++ 2010. , Release , . , , Debug. Release, volatile:
int _tmain(int argc, _TCHAR* argv[]) { int a; //int volatile a; a=1; //break point here is not possible in Release build, unless volatile used printf("%d\n",a); return 0; }