首页 > 其他 > 详细

extern 用法

时间:2018-06-23 11:27:36      阅读:183      评论:0      收藏:0      [点我收藏+]
1  修饰函数,用C函数的方式编译;方便c++代码调用该函数
#ifdef __cplusplus
extern "C" {
#endif

   Interface* create();

#ifdef __cplusplus
}
#endif


.....
#ifdef __cplusplus
extern "C" {
#endif

  Interface* create()
  {
     return new Interface(); 
   }

#ifdef __cplusplus
}
#endif

 

 
 
2  声明函数或者变量,在其他文件中定义;  extern int g_a = 1 在声明时定义,编译会重复声明错误
 
3  static 和 extern  不能同时使用。static修饰的全局变量声明与定义同时进行,只作用于本身编译单元。
 
4 const 和 extern, const作用于本编译模块,两个一起用可以作用于其他模块。
   extern const char g_str[];  // 声明
   const char g_str[] = "123456";  // 定义

extern 用法

原文:https://www.cnblogs.com/bzadhere/p/9216596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!