A brief analysis of some problems in C language header files and libraries _c language

Source: Internet
Author: User
Tags function prototype
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.