我有以下的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