确实的extern" C"必须用C什么影响? [英] Does extern "C" have any effect in C?
本文介绍了确实的extern" C"必须用C什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚使用的externC声明这样的外部函数的一些C code:
I just got some C code that uses extern "C" to declare external functions like this:
extern "C" void func();
这是合法的C?我得到一个错误在这一行,但我不知道这是否是因为这个或别的东西。
Is this valid C? I'm getting an error at this line, but I'm not sure if it's because of this or something else.
推荐答案
没有,这不是有效的C.它应该只在C ++ code被用来指在C code定义的功能。在的externC
应被包围的的ifdef __cplusplus
/ #ENDIF
块:
No, it's not valid C. It should only be used in C++ code to refer to functions defined in C code. The extern "C"
should be surrounded in a ifdef __cplusplus
/#endif
block:
// For one function
#ifdef __cplusplus
extern "C"
#endif
void func();
// For more than one function
#ifdef __cplusplus
extern "C"
{
#endif
void func1();
void func2();
#ifdef __cplusplus
}
#endif
这篇关于确实的extern" C"必须用C什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文