Compiling the following code using gcc-5.1.0 produces a warning:
warning: implicit declaration of function ‘abs’ [-Wimplicit-function-declaration]
int main (void)
printf ("%d\n", abs (-1));
I have compiled the same code with gcc-4.9.2 and it's not producing any warning.
Best How To :
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.