extern "C"
我在文件开头看到一些 C++ 代码,如下所示:
#ifdef __cplusplus
extern "C" {}
#endif
这是什么意思?它是如何工作的?
它用于通知编译器禁用大括号内定义的函数的 C++ 名称修改。http://en.wikipedia.org/wiki/Name_mangling
可能不是这样,但更像是:
#ifdef __cplusplus
extern "C" {
#endif
//some includes or declarations
#ifdef __cplusplus
}
#endif
它告诉编译器对C
指令中声明的任何内容使用名称修饰。
你现在拥有它的方式:
#ifdef __cplusplus
extern "C" {}
#endif
只是死代码。
它指定了一个链接规范。
它告诉链接器如何链接代码。
当您想混合 C 和 C++ 代码时,它很有用。
Extern "C"
- 通知编译器,指出的函数是以 C 风格编译的。