忽略 c 文件中的 stdio.h 文件



可能的重复项:
为什么 #include 不需要 * 使用 printf()?

我在下面给定的代码中遇到了一个问题。

int main()
{
printf("nHello Stack Overflownn") ;
return 0 ;
}

在上面提到的代码中,我留下了"#include"。如果我编译并执行这段代码,输出将按预期打印。但是"#include"是C程序中最重要的东西,我忽略了它,并且仍然编译没有任何错误,但有警告。

为什么会这样?

在 C 中,未声明的函数被隐式地视为返回int并接受int参数。

这是不好的做法,会咬你。例如,如果要打印与 int 大小不同的数据,例如 doublefloat

来自 man gcc

   -nostdlib
       Do not use the standard system startup files or libraries when linking.  No startup files and only the libraries you specify will be
       passed to the linker.  The compiler may generate calls to "memcmp", "memset", "memcpy" and "memmove".  These entries are usually
       resolved by entries in libc.  These entry points should be supplied through some other mechanism when this option is specified.

printf 符号在编译时是未知的,但 libc 在链接隐到二进制...这就是它的工作原理。

最新更新