Access to unstable local variables that are not accessible from outside the function of the observed behavior in C ++?

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.

? , ?

+5
6

, ( , , ).

, , MSVC , . , volatile , , " ". . , MSVC volatile.

, , , , "", - , . , , : , , .

, , ? .

+7

, volatile: , , .

volatile const, , . , , .

+2

Volatile .

volatile int x;
spawn_thread(&x);
x = 0;
while (x == 0){};

, x .

const. , , .

+1

- , ( )

? , x86 , ?

, .

+1

( !), - . volatile , .

+1

. ,

- , ( )

. 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;
}
0

All Articles