且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

差值外部"C"表示"C". vs外部

更新时间:2021-12-04 00:51:48

C ++文件中extern "C"的存在允许从C客户端调用程序代码调用特定的C ++函数.

The presence of extern "C" in a C++ file allows to call the particular C++ function from a C client caller code.

有什么区别?

很久很久以前,C编译器仅通过名称生成代码并处理函数. 它没有考虑参数.

A long, long time ago C-compilers generated code and addressed functions by name only. It didn't consider parameters.

在C ++中引入重载函数时,需要extern "C"为不同的函数指定相同的名称.例如void f()void f(int)是C ++中的两个不同函数.

When overloaded functions were introduced in C++, extern "C" was required to specify the same name for different functions. For example void f() and void f(int) are two different functions in C++.

C ++编译器通过名称处理来完成此任务.它将一些信息添加到与函数参数有关的函数名称中.

The C++ compiler accomplished this via name-mangling. It adds some info to the function name related to the functions parameters.

extern "C"是对编译器的命令,用于引用较早的样式命名约定-无需弄乱".

extern "C" is a command to the compiler to "refer to the older style naming convention - without mangling".