Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

without including <stdio.h>

below given program is working without including <stdio.h>? Why does this work?

int main()
{
    printf("integra");
    return 0;
}
like image 385
venkat Avatar asked Jan 11 '11 04:01

venkat


2 Answers

Definition of printf() is there in libc.so and the dynamic linker will take care of it even if you don't include the header file. During compile time, printf() will be an undefined symbol and it assumes that it may find the definition later on in libc. The header file will just give the proto-type and suppress the compiler(warnings) stating that the definition of the prototype is present in glibc. So basically, the header files are included just to make sure that the definitions are available in our libraries, to help the developer.

like image 173
aTJ Avatar answered Oct 04 '22 01:10

aTJ


in older standard, undeclared function assume int argument and return value. Your char* have same size (32-bit) as int, so everything work.

Just don't do it.

like image 44
J-16 SDiZ Avatar answered Oct 04 '22 02:10

J-16 SDiZ