博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

飞翔,嵌入式linux

linux嵌入式系统必将大行于天下。专注于linux嵌入式系统的搭键,专注于高效稳定软件的开发,专注底层程序调试技术。
  feixiang.cublog.cn

关于作者
姓名:飞翔
Email:loughsky@sina.com
职业:IT
年龄:32
位置:北京
个性介绍:专注在嵌入式操作系统,以及高效程序调试
|| << >> ||
我的分类


const关键字的internal linkage属性
当将const关键字用于声明某个常量时,该标识符自动具备internal linkage属性,即只对相同文件内的函数可见,对其他文件中的函数是不可见的。这可以通过如下的示例程序证明

   
//const1.cpp

#include 
<iostream>

using namespace std;

const int a=1;

void funcA()
{

   cout
<<"cout int A in file const2.cpp have value of "<<a<<endl;
}


// const2.cpp

#include 
<iostream>

using namespace std;

const int a=2;
extern void funcA();
void funcB()

{

   cout
<<"cout int A in file const2.cpp have value of "<<a<<endl;
}


int main()
{

   funcA();
   funcB();
}



编译并执行

g++ const1.cpp const2.cpp
.
/a.out

输出结果

cout int A in file const2.cpp have value of 1
cout 
int A in file const2.cpp have value of 2

 原文地址 http://blog.csdn.net/lovekatherine/archive/2007/06/09/1644971.aspx
发表于: 2008-04-08,修改于: 2008-04-08 16:11,已浏览423次,有评论1条 推荐 投诉


网友评论
网友: 非本站网友 时间:2008-04-20 14:23:35 IP地址:123.128.51.★
不知道C++为什么要搞成这个样。但这对C是不成立的。

 发表评论