华为C语言面试题 3. 此外,extern修饰符可用于指示C或者C++函数的调用规范。比如在C++中调用C库函数,就需要在C++程序中用extern “C”声明要引用的函数。这是给链接器用的,告诉链接器在链接的时候用C函数规范来链接。主要原因是C++和C程序编译完成后在目标代码中命名规则不同
1 #vimprint_extern.c 2 3 #include <stdio.h> 4 5 extern void print_extern()//这里用不用extern都可以 6 7 { 8 9 printf("helloextern test!!\n"); 10 11 } 12 13 #vim extern_test.c 14 15 #include <stdio.h> 16 17 18 19 extern void print_extern();//其实这里用不用extern都是可以的 20 21 main() 22 23 { 24 25 print_extern(); 26 27 } 编译: 28 #gcc –c print_extern.c –o print_extern.o 29 30 #gcc print_extern.o extern_test.c –o extern_test 31 #./extern_test |