zoukankan      html  css  js  c++  java
  • Volatile关键字

     

    Volatile关键字

    ·         The compiler assumes that, at any point in the program, avolatile variable can be accessed by an unknown process that uses or modifies its value. Therefore, regardless of the optimizations specified on the command line, the code for each assignment to or reference of avolatile variable must be generated even if it appears to have no effect.

    If volatile is used alone, int is assumed. Thevolatile type specifier can be used to provide reliable access to special memory locations. Usevolatile with data objects that may be accessed or altered by signal handlers, by concurrently executing programs, or by special hardware such as memory-mapped I/O control registers. You can declare a variable asvolatile for its lifetime, or you can cast a single reference to bevolatile.

     

    ·         直接存取原始内存地址

               能够防止编译器优化。

                编译器每次用到这个变量的值的时候都会直接从内存中读取而不是读取寄存器中的备份。通过反汇编可能会发现一些问题(待续).http://www.dutor.net/index.php/2010/08/volatile-const/


  • 相关阅读:
    BZOJ3129/洛谷P3301方程(SDOI2013)容斥原理+扩展Lucas定理
    Dilworth定理
    字符串
    hash
    李超线段树(segment[HEOI2013]-洛谷T4097)
    连通数[JSOI2010]-洛谷T4306
    主席树
    splay
    树链剖分
    受欢迎的奶牛-洛谷2341
  • 原文地址:https://www.cnblogs.com/johnpher/p/2570621.html
Copyright © 2011-2022 走看看