Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top