c语言common类型变量,[讨论]关于C语言数据存储类型关键字static的问题

[讨论]关于C语言数据存储类型关键字static的问题

(2012-04-09 23:44:47)

标签:

关键字

存储

c语言

杂谈

[讨论]关于C语言数据存储类型关键字static的问题在C语言数据存储类型关键字中有一个static,static有三种链接类型(linkage

type),即static with no linkage, static with internal linkage 以及

static with external linkage。我在一本书上,即C Primer Plus,看到对static with

no linkage的描述,如下:

Static, no linkage— A variable declared in a block with the static

storage class modifier belongs to the "static, no

linkage" storage class. It has static storage

duration, block scope, and no linkage. It is initialized just once,

at compile time. If not initialized explicitly, its bytes are set

to 0.

译文:静态存储类型,无链接类型——在一个程序段中声明的变量,具有静态存储类型,其所属的存储类型为“静态存储类型,无链接类型”。它具有静态存储持续期,程序段作用域,无链接。它只可初始化一次,在编译时进行。如果没有经过明确初始化则具有该存储类型的变量所有字节都设置为0。

按照这样的对“static, no linkage”的定义,则具有该存储类型的变量就只具有“block

linkage”,即它只在一个程序段中起作用,言下之意就是在程序的其他地方不起作用。

而稍后我又在该书的练习题中发现这样的一个问题:

Which storage classes create variables that persist for the

duration of the containing program?

译文:何种存储类型能够产生出变量,该变量能够在其所处的程序范围内持续存在?

给出的参考答案是:

The static, no linkage storage class, the static, internal linkage

storage class, and the static, external linkage storage

class.

译文:静态,无链接存储类型、静态,内部链接存储类型以及静态,外部链接类型

按照这样的参考答案http://www.tnbwang.com,也就是说static no

linkage类型的变量不只可以在其所处的程序段范围内存在还可以持续在整个程序范围内存在了?这和前面提出的static, no

linkage类型的定义不矛盾吗?而且我做了一个测试程序(如下)也证明定义是正确的而这个练习问题的参考答案不正确。

#include

int main(void){

int a = 5;

int b = 4;

if(a > b){

static int c = a;//

分享:

a4c26d1e5885305701be709a3d33442f.png喜欢

0

a4c26d1e5885305701be709a3d33442f.png赠金笔

加载中,请稍候......

评论加载中,请稍候...

发评论

登录名: 密码: 找回密码 注册记住登录状态

昵   称:

评论并转载此博文

a4c26d1e5885305701be709a3d33442f.png

发评论

以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值