Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printf gives WARNING only

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.

like image 391
akash Avatar asked Dec 08 '22 22:12

akash


1 Answers

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.

like image 188
pb2q Avatar answered Dec 26 '22 12:12

pb2q