您的位置:首页 > 编程语言 > C语言/C++

extern c 解释

2017-05-28 17:39 225 查看
extern “C”修饰的变量和函数是按照c的方式编译的

如果想用c++方式编译c代码,需要特殊标识

方法

#if defined(__cplusplus) || defined(c_plusplus)
extern "C"{
#endif

...

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif


举例

void func(int a, char b, float c){}


# g++ *.cpp -S
# cat *.s
.file   "*.cpp"
.text
.globl  _Z4funcicf //func+int+char+float
.type   _Z4funcicf, @function


#if defined(__cplusplus) || defined(c_plusplus)
extern "C"{
#endif

void func(int a, char b, float c){}

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif


# g++ *.cpp -S
# cat *.s
.file   "*.cpp"
.text
.globl  func
.type   func, @function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 extern-c