Access volatile variables that cannot be accessed from outside the observable behavior of functions in the C language?

In C 03, the standard observable behavior (1.9 / 6) includes reading and writing volatile data Now I have this Code:

int main()
{
    const volatile int value = 0;
    if( value ) {
    }
    return 0;
}

It formally initializes a volatile variable and then reads it Visual C 10 sends out machine code, makes space on the stack by pushing DWORD there, writes zero to the stack position, and then reads the position

It doesn't mean anything to me – no other code or hardware may know the location of the local variable (because it is in automatic storage), so it's unreasonable to expect the variable to be read / written by any other party, so it can be eliminated in this case

Allow to eliminate access to this variable? Accessing volatile local, which address is not known to any other party's observable behavior?

Solution

The entire stack of threads may be located on a protected memory page, which contains a handler that records all reads and writes (and of course allows them to complete)

However, I don't think MSVC really cares about whether or how to detect memory access Among other things, it understands that volatility means "don't apply optimization to this object." So it didn't It makes no sense because MSVC is not interested in accelerating the use of volatile

Because it depends on the implementation, whether and how to actually observe observable behavior, I think if the hardware details know that access cannot be detected, the implementation can "cheat" Observable behavior without physically detectable effects can be skipped: no matter what the standard says, the method of detecting non-compliance is limited to physically possible

If an implementation does not meet the standards in the forest and no one notices, does it make a sound? Something like that

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>