Compiling the following code using gcc-5.1.0 produces a warning:
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.
The abs()
function is declared in <stdlib.h>
which you've not included.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With