函数abs的隐式声明 - gcc-5.1.0 Implicit declaration of function abs - gcc-5.1.0

The abs() function is declared in <stdlib.h> which you've not included. abs()函数在<stdlib.h>声明,你没有包含它。

fabs() function is declared in <math.h>

 

函数abs的隐式声明 - gcc-5.1.0

Implicit declaration of function abs - gcc-5.1.0

Compiling the following code using gcc-5.1.0 produces a warning: 使用gcc-5.1.0编译以下代码会产生警告:

warning: implicit declaration of function ‘abs’ [-Wimplicit-function-declaration]

Code: 码:

#include <stdio.h>
#include <math.h>

int main (void)
{
  printf ("%d\n", abs (-1));

  return 0;
}

I have compiled the same code with gcc-4.9.2 and it's not producing any warning. 我用gcc-4.9.2编译了相同的代码,并没有产生任何警告。

2 个回复

The abs() function is declared in <stdlib.h> which you've not included. abs()函数在<stdlib.h>声明,你没有包含它。

GCC 4.9.2 didn't complain because the default compilation mode was C89/C90 ( -std=gnu89 ) and functions did not need to be declared before being used in C89 as long as they returned an int , but the default compilation mode was changed to C11 ( -stdd=gnu11 ) in GCC 5.1.0 (see the release notes ) and in C11 functions must be declared (or defined) before they are used. GCC 4.9.2没有抱怨,因为默认编译模式是C89 / C90( -std=gnu89 ),并且只要它们返回一个int ,就不需要在C89中使用之前声明函数,但默认的编译模式是在GCC 5.1.0中更改为C11( -stdd=gnu11 )(参见发行说明 ),在使用之前必须声明(或定义)C11函数。

Try to include the <stdlib.h> in your code. 尝试在代码中包含<stdlib.h> 。 The abs() function is defined inside the <stdlib.h> abs()函数在<stdlib.h>定义

使用gcc编译器隐式int和隐式声明函数 - implicit int and implicit declaration of functions with gcc compiler

我读了c99标准: 但是当我尝试使用-pedantic在c99模式下使用gcc编译器编译此代码时 我期待2个错误,但我只收到2个警告: 它们不应该是c99中的错误吗? http://gcc.gnu.org/c99status.html在这两种情况下都写了“完成”。 ...

 2012-06-23 16:25:07  3  2144   cc99 
函数的隐式声明 - Implicit declaration of functions

我从isdigit和isalpha函数中收到此错误 我的代码是: 我如何摆脱这些警告? ...

 2014-02-08 01:43:16  1  5567   clinux 
函数的隐式声明 - implicit declaration of function

当不包含正确的头文件时,GCC通常会发出此警告。 此链接-&gt; www.network-theory.co.uk/docs/gccintro/gccintro_19.html说,因为函数声明是隐式的(而不是通过标头显式声明的),所以实际上可能会将错误的参数类型传递给函数,结果不正确。 我 ...

 2011-06-27 03:51:19  2  2258   cgcccompiler-constructiongcc-warning 
函数的隐式声明sbrk() - Implicit Declaration of Function sbrk( )

我正在尝试创建自己的malloc函数,但尚未完成。 这是我的代码的相关部分: mymalloc.h : mymalloc.c 在sbrk(sizeof(tmp)); 在mymalloc.c一部分中,我得到了"Implicit declaration of functio ...

 2017-12-25 07:42:33  1  628   c 
函数“ wiringPilSR”的隐式声明 - implicit declaration of function 'wiringPilSR'

我正在尝试使用connectioningPI的wiringPilSR将中断附加到引脚。 我的代码如下所示: 当我尝试在Geany中构建代码时,出现警告“ implicit declaration of function 'wiringPilSR' ”和错误“ undefined ref ...

 2017-02-25 22:22:37  1  268   craspberry-pigeanywiringpiimplicit-declaration 
错误:函数的隐式声明 - Error: Implicit declaration of function

我下面的代码有错误。 它说函数的隐式声明在C99中无效。 我不太确定如何解决此问题。 ...

 2014-10-20 08:50:39  1  2006   objective-ccc99 
mkstemp函数的隐式声明 - mkstemp implicit declaration of function

我的功能mkstemp()有问题。 cygwin上的GCC编译器会生成警告: GCC标志: -std=c99 -Wall 包括: ...

 2014-07-15 12:19:05  1  962   ccygwinmkstemp 
函数x的隐式声明 - Implicit declaration of function x

我很清楚函数原型,这个错误似乎是一个函数声明错误,这意味着我真的很困惑,为什么我看到这个警告,从而错误。 这几乎就像gcc完全忽略了我的函数原型。 这是编译器错误吗? 为了简洁起见,我没有在单独的头文件中声明此函数,尽管它应该没有区别。 gcc输出: 码: ...

 2013-07-24 16:45:53  4  4440   calgorithmprime-factoring  
函数fseeko的隐式声明 - Implicit declaration of function fseeko

我正在尝试将fseeko函数与GCC编译器结合使用,以处理C中大于4GiB的文件。现在,一切正常,我能够处理超过4GiB的文件,但GCC一直在抱怨fseeko函数是隐式声明的。 这是生成此消息的源代码的最小工作示例: 我在任何地方都找不到要解决此警告的标头。 GCC给出的确切警告是: ...

 2016-11-23 17:20:52  1  765   clarge-filesfseek 
10 函数的隐式声明 [重复] - Implict Decleration of Function [duplicate]

这个问题在这里已经有了答案: 警告:函数的隐式声明(9 个回答) 11 个月前关闭。 首先我不得不说我的大脑因 ...

 2020-10-05 14:52:11  3  83   cfunctionimplicit 


 
 
https://stackoom.com/cn_en/question/23m3i
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章