うまくいけば、これは非常に簡単な質問です。以下は、私が持っている C pgm (test.c) です。
#include <stdio.h>
//#include <stdlib.h>
int main (int argc, char *argv[]) {
int intValue = atoi("1");
double doubleValue = atof("2");
fprintf(stdout,"The intValue is %d and the doubleValue is %g\n", intValue, doubleValue);
return 0;
}
stdlib.h の atoi() と atof() を使用していますが、そのヘッダー ファイルは含めていません。pgm (gcc test.c) をコンパイルしましたが、コンパイラ エラーは発生しません。
pgm (./a.out) を実行すると、間違った出力が表示されます。
The intValue is 1 and the doubleValue is 0
ここで、(#include の前のコメントを削除して) stdlib.h をインクルードし、再コンパイルして再度実行します。今回は正しい出力が得られます。
The intValue is 1 and the doubleValue is 2
stdlib.h が含まれていないことについてコンパイラが文句を言わず、atoi()、atof() 関数を使用できるのはなぜですか?
私のgcc情報:
$ gcc --version
gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)
どんな考えでも大歓迎です!