extern,auto,static,register区别

extern,auto,static,register区别:

存储类别, 指明变量的存储形式(位置生存期),分为全局、局部、静态、动态四种形式:

extern:全局(外部);   // 在一个类中定义了全局变量int width,其他类中就不能在定义width全局变量了,否则link阶段会通不过

static:静态(局部);

auto:  自动(局部、动态);   //auto就是我们平时使用的局部变量的样式

register:寄存器变量。 

注意:存储类别是任选项,缺省情况下,在函数外部默认为全局,在函数内部默认为“自动”类别。

更详细的描述:

http://stackoverflow.com/questions/3684760/where-are-the-local-global-static-auto-register-extern-const-volatile-var

猜你喜欢

转载自quding0308.iteye.com/blog/1851551