Can anyone tell me why not including stdio.h
and still using the printf
function only gives a warning on gcc?
warning: incompatible implicit declaration of built-in function ‘printf’
Rather this should be a compile error, as we are including a function that is not declared.
Does this have something to do with the linking procedure? Please elaborate.
When you don't supply signatures for functions that you use in your code, the compiler will (implicitly) make some assumptions about what the unknown function accepts as an argument list, and returns as result.
These assumptions are based on your usage of the function, so e.g. given printf("%s", (char *) string)
, the compiler will decide that printf
is a function that takes exactly 2 char *
- not a variable argument list - and returns an int
.
Problems can then occur during linking, when these assumptions turn out to be incompatible with the actual function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With