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>
定義