为什么GCC报告和QUOT;功能'圆'隐式声明"? [英] Why does gcc report "implicit declaration of function ‘round’"?

查看:170
本文介绍了为什么GCC报告和QUOT;功能'圆'隐式声明"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的C code:

I have the following C code:

#include <math.h>

int main(int argc, char ** argv)
{
    double mydouble = 100.0;
    double whatever = round(mydouble);

    return (int) whatever;
}

当我编译,我得到了警告:

When I compile this, I get the warnings:

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带来了声明轮()为范围。我检查了我的ANSI标准(C99是我唯一的副本),这证实了round()函数在math.h中头的存在。缺少什么我在这里?

I'm rusty with C, but I thought that the #include brought a declaration for round() into scope. I've checked my ANSI standard (C99 is the only copy I have) which confirms that the round() function exists in the math.h header. What am I missing here?

编辑:编译器是在Ubuntu(勇敢,IIRC)GCC 4.3.2。运行GCC -E给出了:

The compiler is GCC 4.3.2 on Ubuntu (intrepid, IIRC). Running gcc -E gives:

$ gcc -E round_test.c | grep round
# 1 "round_test.c"
# 1 "round_test.c"
# 2 "round_test.c" 2
    double whatever = round(mydouble);

所以显然不会在头被发现。定义

so the definition obviously isn't being found in the headers.

推荐答案

我看到你使用gcc。

在默认情况下,海湾合作委员会使用标准的类似C89。您可能要逼它使用C99标准(它符合的部分)

By default, gcc uses a standard similar to C89. You may want to "force" it to use the C99 standard (the parts it complies with)

gcc -std=c99 -pedantic ...

手册报价

在默认情况下,GCC提供了一些
  扩展的C语言上
  少数情况下,与C冲突
  标准。见扩展到C
  语系。在-std使用
  上面列出的选项将禁用
  这些扩展他们的冲突
  与C标准版本选择。
  您也可以选择延长
  C语言版本明确
  与-std = gnu89(C89为GNU带
  扩展)或-std = gnu99(对C99
  与GNU扩展)。默认的,如果
  没有C语言的方言选项
  给予,是-std = gnu89;这将改变
  到-std = gnu99在未来的版本
  当C99支持完成。一些
  功能是C99的一部分
  标准被接受作为扩展
  C89模式。

By default, GCC provides some extensions to the C language that on rare occasions conflict with the C standard. See Extensions to the C Language Family. Use of the -std options listed above will disable these extensions where they conflict with the C standard version selected. You may also select an extended version of the C language explicitly with -std=gnu89 (for C89 with GNU extensions) or -std=gnu99 (for C99 with GNU extensions). The default, if no C language dialect options are given, is -std=gnu89; this will change to -std=gnu99 in some future release when the C99 support is complete. Some features that are part of the C99 standard are accepted as extensions in C89 mode.

这篇关于为什么GCC报告和QUOT;功能'圆'隐式声明&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆