IOS 开发学习六 extern 和 static 对函数的作用

来源:互联网 发布:淘宝的旗舰店是正品吗 编辑:程序博客网 时间:2024/05/17 02:13

一、extern 与函数

如果一个程序有多个.c源文件  ,每个源文件在编译后会对应一个.obj文件 ,这些目标文件之间可能有关联,把它们链接在一起再生成可执行文件 。

  • 外部函数:当前文件定义的函数允许其他文件访问。不可以有同名的名部函数;
  • 内部函数:当前文件定义的函数不允许其它文件访问、调用,只能在内部使用,称为内部函数。内部函数可以重名。
</pre>main.c<pre name="code" class="objc">////  main.c//  firstC////  Created by 谢厂节 on 15/1/13.//  Copyright (c) 2015年 xundh. All rights reserved.//#include <stdio.h>#include "waibu.h"//extern void waibu(); //默认就是extern  所以可以省略int main(int argc,const char *argv[]){    waibuhanshu();}

waibu.c
#include "waibu.h"extern void waibuhanshu(){ //默认就是extern    printf("test");}


waibu.h
#ifndef __firstC__waibu__#define __firstC__waibu__#include <stdio.h>#endif /* defined(__firstC__waibu__) */void waibuhanshu();

二、static与函数

与extern对应,static指函数是内部函数,不允许外部调用。

0 0
原创粉丝点击