一、extern "C"(1)
•extern “C”的最大作用就是实现C\C++混合编程,比如C\C++的函数互调
•注意:extern后面必须是大写的C
•被extern “C”修饰的变量和函数是按照C语言方式编译和连接的
Ø也就是说extern “C” void test(int a, int b)被编译器产生的函数名就是_test,不再是类似_test_int_int之类的名称
Ø
•下面的写法是等价的:

extern "C" void test(int a, int b);

extern "C" void test2(int a, int b);

等价于

extern "C"

 

二、extern "C"(2)

•由于C语言不支持extern “C”的语法,所以严谨起见,一般C++头文件的函数声明会这么写:

#ifdef __cplusplus

extern "C"

{

#endif

   

void test(int a, int b);

void test2(int a, int b);

   

#ifdef __cplusplus

}

#endif

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-10-21
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
相关资源
相似解决方案