问题描述
示例:
byte number = 128;
Convert.ToString(number,2);
问题:
- 为什么还要编译(即生成
/* lib.c */ #include <stdio.h> int f1(int a) { printf("%d\n",a); return 0; } /* t3.c */ int main() { f1(); return 0; } gcc -c -o lib.o lib.c && gcc t3.c lib.o && ./a.exe t3.c: In function 'main': t3.c:3:2: warning: implicit declaration of function 'f1' [-Wimplicit-function-declaration] 3 | f1(); | ^~ 1 clang -c -o lib.o lib.c && clang t3.c lib.o && ./a.exe t3.c:3:2: warning: implicit declaration of function 'f1' is invalid in C99 [-Wimplicit-function-declaration] f1(); ^ 1 warning generated. 1
)? - 为什么没有像
a.exe
这样的链接器错误? - 是否违反约束条件?
解决方法
为什么还要编译(即生成a.exe)?
编译器支持向后兼容。在C99标准之前,可以在不提供其声明的情况下调用函数。 C编译器不会像C ++编译器那样产生错误的函数名称。
为什么没有链接器错误(如错误):实参太少 呼叫f1,预期为1,是否为0?
链接器找到了外部名称f1。因此,解决了对f1的引用。链接器不会检查函数的调用方式。