// ============================================================================ // p1c03_45 — 3.14.3 extern “C”浅析 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; // --- 原文片段 [58954439:46] 3.14.3 extern “C”浅析 --- #define _CRT_SECURE_NO_WARNINGS #include using namespace std; #if 0 #ifdef __cplusplus extern "C" { #if 0 void func1(); int func2(int a, int b); #else #include"MyModule.h" #endif } #endif #else extern "C" void func1(); extern "C" int func2(int a, int b); #endif int main(){ func1(); cout << func2(10, 20) << endl; return EXIT_SUCCESS; } // --- 为使本示例作为独立目标可链接,就地提供 func1/func2 的 extern "C" 定义 --- // (原文仅声明;定义在配对的 MyModule.c。此处补最小实现以自洽编译运行。) extern "C" void func1(){ printf("hello world!"); } extern "C" int func2(int a, int b){ return a + b; } // --- main ---