Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“extern”是怎么做的;";在C+中工作+;? 我看到C++中的一些代码使用了代码>外部“C”文件的开头如下: #ifdef __cplusplus extern "C" {} #endif_C++_Extern C - Fatal编程技术网 外部“C”文件的开头如下: #ifdef __cplusplus extern "C" {} #endif,c++,extern-c,C++,Extern C" /> 外部“C”文件的开头如下: #ifdef __cplusplus extern "C" {} #endif,c++,extern-c,C++,Extern C" />

“extern”是怎么做的;";在C+中工作+;? 我看到C++中的一些代码使用了代码>外部“C”文件的开头如下: #ifdef __cplusplus extern "C" {} #endif

“extern”是怎么做的;";在C+中工作+;? 我看到C++中的一些代码使用了代码>外部“C”文件的开头如下: #ifdef __cplusplus extern "C" {} #endif,c++,extern-c,C++,Extern C,这是什么意思?它是如何工作的?它指定了一个 它告诉链接器如何链接代码 当您想要时,它很有用。它可能不是这样的,而是更像: #ifdef __cplusplus extern "C" { #endif //some includes or declarations #ifdef __cplusplus } #endif 它告诉编译器对指令中声明的内容使用Cname mangling 您现在拥有的方式: #ifdef __cplusplus extern "C" {} #endif

这是什么意思?它是如何工作的?

它指定了一个
它告诉链接器如何链接代码


当您想要

时,它很有用。它可能不是这样的,而是更像:

#ifdef __cplusplus 
extern "C" {
#endif

//some includes or declarations

#ifdef __cplusplus 
}
#endif
它告诉编译器对指令中声明的内容使用
C
name mangling

您现在拥有的方式:

#ifdef __cplusplus 
extern "C" {} 
#endif

只是死机代码。

<代码>外部> C”/代码>通知编译器,注意的函数是用C风格编译的。

< P>它用来通知编译器禁用括号内定义的函数的C++名称。p> 但是我看到的代码是:#ifdef ucplusplus extern“C{}#endif,那么它是错误的代码吗?@ratzip它没有错,它只是死代码。它不做任何事情。它告诉编译器(不是链接器)使用C++的函数,而不是C++。这不仅包括名称损坏,还包括传递参数的约定,以及其他可能的事情。@JamesKanze你是说链接器不需要知道名称损坏吗?一点也不。编译器会弄乱名称。链接器把它给的名字和它要的名字连接起来。关于外部“c”的好信息:@Nawaz:是谁说的?
“C”
是+1,你在一行中说了我在100中要说的话。做得好。