Chinaunix首页 | 论坛 | 博客
  • 博客访问: 132936
  • 博文数量: 75
  • 博客积分: 3483
  • 博客等级: 中校
  • 技术积分: 820
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-07 08:31
文章分类

全部博文(75)

文章存档

2011年(53)

2010年(22)

我的朋友

分类: C/C++

2011-01-05 14:43:13

A static function has a name visible in that translation unit only. A
normal function has a name visible across the entire program.
If you were to have two source files:

static int foo() {
return 0;
}
int bar() {
return 0;
}

(both files look the same)
you would get "function already defined" errors for bar, but foo would
compile absolutely OK.

在函数的返回类型前加上关键字static,函数就被定义成为静态函数。

  函数的定义和声明默认情况下是extern的,但静态函数只是在声明他的文件当中可见,不能被其他文件所用。

  定义静态函数的好处:

  <1> 其他文件中可以定义相同名字的函数,不会发生冲突

  <2> 静态函数不能被其他文件所用。


 

阅读(655) | 评论(1) | 转发(0) |
0

上一篇:vi 常用命令

下一篇:条件分支

给主人留下些什么吧!~~

chinaunix网友2011-01-06 14:48:17

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com