static变量的生存期及作用域

原文:http://bytes.com/topic/c/answers/925791-scope-global-static-variable


重点部分:

Duration (more formally called storage class)
Duration refers to the interval during which the memory associated with a variable is used for that variable. Storage duration can be static, automatic, or allocated. Variables defined outside of block scope or with the static keyword have static duration and are guaranteed to exist until the program ends. Variables defined inside of block scope, but without the static keyword, have automatic duration and are only guaranteed to exist until the flow of control leaves that block. Variables created by malloc, calloc, or realloc have allocated duration and exist until explicitly destroyed by free or realloc or the program ends, whichever comes first.

Linkage
Linkage refers to the scope within which a variable name is recognized. Linkage can be none, internal, or external. Variables defined within a block have no linkage -- they cannot be accessed outside of that block. Variables defined outside of block scope and with the static keyword have internal linkage -- they can only be accessed locally within the compilation unit (source file) in which they appear. Variables defined outside of block scope without the static keyword have external linkage -- they can be accessed from any compilation unit that has a matching declaration.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值