免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: tianxiaogang12
打印 上一主题 下一主题

全局变量问题 又搞不清了 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2010-04-02 15:04 |只看该作者
回复 20# 雨过白鹭洲


    5. If the declaration of an identifier for a function has no storage-class specifier,its linkage
is determined exactly as if it were declared with the storage-class specifier extern.If
the declaration of an identifier for an object has file scope and no storage-class specifier,
its linkage is external.

这段话是从哪摘录的? 是《the c programming language》吗?

大体理解是
a.如果在函数里声明的标示符,没有存储类型说明符的话,该标示符就相当于extern 声明的标示符
b.如果在文件作用域里声明的标示符,没有存储类型说明符的话,该标示符也相当于extern 声明的标示符

是这么翻译的吗?

如果是按上面的理解在一个函数里也可以这么声明,如:
       void func ()
          {
                int i;
                int i;
          }
这肯定会报错的 我试过

论坛徽章:
0
22 [报告]
发表于 2010-04-02 16:58 |只看该作者
回复  雨过白鹭洲


    5. If the declaration of an identifier for a function has no storag ...
tianxiaogang12 发表于 2010-04-02 15:04



    大体理解是
a.如果在函数里声明的标示符,没有存储类型说明符的话,该标示符就相当于extern 声明的标示符
b.如果在文件作用域里声明的标示符,没有存储类型说明符的话,该标示符也相当于extern 声明的标示符

a理解有误,这里的标识符说的就是函数
b的理解是对的

这段话来自C99 Standard

论坛徽章:
0
23 [报告]
发表于 2010-04-02 17:01 |只看该作者
函数里定义的变量,除非是定义在别处的全局变量,还需要Link吗?

void func ()
          {
                int i;
                int i;
          }
当然会报错
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP