Click to See Complete Forum and Search --> : Why do some libraries not need including?


ArtVandelay
01-05-2003, 07:30 AM
I was messing around the other day, just
making a mini program to check out the IP
address structures (sockaddr_in and sockaddr_in6)
and I did some printf statements so I could get some visuals on what was going on.

Anyways, I had stupidly forgot to include stdio.h,
but it compiled anyways!

I am now noticing quite a few standard library functions that are working without me making the includes. Can anyone tell me why this is? I'd like to turn this "feature" off, if possible so I don't accidently create any bad code where I forget includes.

This is gcc on RedHat 8.0 I'm using.

bastard23
01-06-2003, 11:48 AM
ArtVandelay,

Basically, stdio.h could be included by another include file. If this isn't the case here is what is going on.

C doesn't require a prototype, so your code is compiling and since you are using std c library stuff, it is linking correctly with libc. Try adding -Wimplicit-function-declaration to your gcc command line. It will report this specific problem. C++, by design, makes this an error (requires prototypes). Also try:

gcc -Wall -Werror file.c -o file.o

This will report all of the warnings (-Wall), and make all warnings errors (-Werror) and won't compile.

Good Luck,
chris

ArtVandelay
01-10-2003, 10:17 PM
A late thank you.

Yes, these options are good for avoiding problems with what seemed to be auto-includes.