<标识符>

  限定符的作用是限定变量,而使被限定的变量具有特殊的属性,以达到我们变成的目的。通常有局部变量和全局变量,局部变量定义在函数内被,期生命周期在函数被调用的时间内;而全局变量定义在函数外部,其生命周期,贯穿始终。

  接着我们说说,在嵌入式底层开发,常用的限定符:static, volatile, extern。一下举例说明:

  volatile is typically used for hardware address and for data shared with other programs .告诉编译器,不要优化,因为,该变量可能在别处改变。

  //Module A

  int foo;    //Meant to be modified in this module only

  volatile int bar;  //Value can change unexpectedly outside of this module.

  //Module B

  extern int foo; //we can read this value defined in Module A,but should not modify it.

  extern int bar; //Since declared volatile in Module A,we can read and modify this variable.

原文地址:https://www.cnblogs.com/michael2016/p/6926391.html