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编译了相同的代码,并没有产生任何警告。
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>
定义