extern C:两层含义:
extern 与static,指定范围 外部可调用
extern C声明(不是定义)的变量或者函数 用C风格的编译方式编译
//
某个头文件,比如叫 ExternTest.h 中
extern
int
iExtern;
//
这样就是一个变量声明——而不是定义,因为没有分配存储空间
//
这以后就可以引用这个变量,而这个变量的存储于下面的 int iExtern; 的那个位置分配
//
某个源文件,比如叫 ExternTest.c 中
int
iExtern;
//
不能写成 static int iExtern; 因为这样就不再是全局的变量——不具有External Linkage性质
//
也不能写成 extern int iExtern; 因为这样就不再是一个定义,
//
另一个源文件,比如叫 main.c 中
#include
"
ExternTest.h
"
//
......其他代码
int
iTwiceExt
=
iExtern
*
2
;
//
这里就可以直接用iExtern这个变量,因为在 ExternTest.h 声明过了
//
......其他代码