Without a header (stdio.h) file, how the following code might work?

How can this following code work without including a header file for the printf function?

int main(){
printf("%d",1);
return 0;}

      

+3


source to share


1 answer


Note: This is a wavy answer that would be roughly correct. Someone who knows the details of gory (like gcc for example) can enlighten both of us. Here:

Because in C - at least for some compilers - implicitly defined functions are fine. So it compiles it and then passes it to the linker. It sees a link to printf

, and since the default linker references the C runtime library, it resolves that symbol to the correct function.



My guess is that an implicit function like this will get a default signature usually expecting an int to return. As for the function arguments, they cannot be checked at compile time because the compiler does not know what the actual function signature is. So it will just use the standard calling convention, eg. pass arguments using registers or something.

+2


source







All Articles