• 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/


  • 相关阅读:
    Vue状态管理
    Vue延迟点击
    Vue路由
    简单的队列应用
    Uncaught SyntaxError: Unexpected token )
    视频转码
    判断是否为视频文件
    Press ^C at any time to quit.
    Node.js学习
    YUM安装LAMP与LNMP
  • 原文地址:https://www.cnblogs.com/johnpher/p/2570621.html
Copyright © 2020-2023  润新知