2
votes

What is the reason for including standard header files in C such as stdio.h stdlib.h etc.. gcc compiler just show a warning and declaring it implicitly like

implicit declaration of function 'printf'

and program executing successfully...
Rather than to remove the warning, is there any reason to include header files?

1
FILE to name one struct that is useful and declared in stdio.h - AndersK
You already answered your question, the point of including the headers is to stop the compiler from generating a warning. Stopping the compiler from generating the warning is a good thing. The fact that the compiler shows you a warning is also a good thing. Btw if it's easier you can put common includes together and just say #include "stanard_headers.h" or something like that to make it less typing if you want. - Brandin

1 Answers

4
votes

Well yes, of course there's a reason.

The reason is that with the headers, you get the proper declarations, otherwise you get the implicit declaration where every function is assumed to return int. Since there are many functions (for instance malloc()) that don't return int, assuming that they do can be very harmful.

With function declarations the compiler can actually check that arguments and return values match the usage, which is very good.

Also, there are of course cases where headers declare data types, enumerations and so on that you need, there's more than functions in headers.