2

重複の可能性:
printf()を使用するために#include <stdio.h>が*必要ない*のはなぜですか?

以下のコードで問題が発生しています。

int main()
{
printf("\nHello Stack Overflow\n\n") ;
return 0 ;
}

上記のコードでは、「#include」を含めて残しました。そして、このコードをコンパイルして実行すると、出力は期待どおりに出力されます。しかし、「#include」はCプログラムで最も重要なものであり、私はそれを無視しましたが、それでもコンパイルはエラーなしで警告付きで実行されます。

なぜこうなった?

4

3 に答える 3

2

Cでは、宣言されていない関数は暗黙的にとを返し、引数intを取ると見なされます。int

これは悪い習慣であり、あなたを噛むでしょう。たとえば、doubleまたはのように、同じサイズのintではないデータを印刷する場合ですfloat

于 2012-11-28T10:17:44.557 に答える
0

mangccから

   -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.
于 2012-11-28T10:19:25.323 に答える
0

printfシンボルはコンパイル時には不明ですが、libcは暗黙的にバイナリにリンクされています...そしてそれがどのように機能するかです。

于 2012-11-28T10:19:49.653 に答える