我有以下的C代碼:爲什麼gcc報告「函數的隱式聲明」round'「?
#include <math.h>
int main(int argc, char ** argv)
{
double mydouble = 100.0;
double whatever = round(mydouble);
return (int) whatever;
}
當我編譯,我得到了警告:
round_test.c: In function ‘main’:
round_test.c:6: warning: implicit declaration of function ‘round’
round_test.c:6: warning: incompatible implicit declaration of built-in function ‘round’
我生疏C,但我認爲的#include帶來的聲明對於round()進入範圍。我檢查了我的ANSI標準(C99是我唯一的副本),它證實了round()函數存在於math.h頭文件中。我在這裏錯過了什麼?
編輯:編譯器是Ubuntu上的GCC 4.3.2(intrepid,IIRC)。運行gcc -E給出:
$ gcc -E round_test.c | grep round
# 1 "round_test.c"
# 1 "round_test.c"
# 2 "round_test.c" 2
double whatever = round(mydouble);
所以在頭文件中顯然沒有找到定義。
謝謝,-std = c99似乎解決了它。我沒有意識到round()是C99的補充(當然,我所有的參考都是C99,而忽略了這一點) – 2009-11-23 15:32:55
(驚訝的樣子)round()真的是C99的補充嗎? – 2009-11-23 15:43:56
對,C89沒有描述'round()'函數(當然編譯器可以提供它作爲擴展)。 – pmg 2009-11-23 15:50:48