Compiler header files using gcc do not contain stdlib.h, use the Atoi function (atoi function is declared in stdlib.h), compile without error
If you add the-wall option at compile time, there will be a warning, excuse me, why is this?
This is because the C language is a very silly rule: if a function does not declare a function prototype, its return value type is int (the so-called implicit declaration). Since atoi exactly returns int, you do not complain even if you do not include its header file. As for this warning, it is to avoid you making mistakes by forgetting to declare a function prototype.
The compiler does not need to know that it has already been defined, as it returns an int for a function prototype that has not been defined.
That is, when you call Atoi with a parameter list, the compiler already knows what the parameter list of the function is, it just doesn't know the return value, in which case what extra stuff does the compiler need? Of course it can pass.
Note: The compiler does not care which header file is defined for a function, it only needs to know what the prototype of the function is.
Copy Code code as follows:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i;
Double F;
Char b[5] = "23";
Char c[5] = "2.3";
i = atoi (b);
f = atof (c);
printf ("i=%d f=%lf\n", I, f);
return 0;
}
GCC Test.c-o test does not have any warning
Gcc-wall Test.c-o Test
A warning appears: W9.c:in function ' main ':
W9.c:9: warning:implicit declaration of function ' Atoi '
W9.C:10:WARNING:IMPLICIT declaration of the function ' Atof '
Output Results:
I=23 f=1717986918.000000
Plus #include<stdlib.h>, the results are normal.
It seems atoi and Atof are in the C standard library glibc, but it's strange why the C standard library functions sqrt and POW are not in glibc