multiple inclusions of a header file

Jan 21, 2009 at 9:35pm
I have read about how to avoid multiple inclusions of header files.But what problem does including multiple inclusions of the same header actually cause? Im still new to this and just trying to learn ^_^ I understand that you get an error if you try to double include a header file (from what i've read online) but does this cause your program to basically generate 2 of everything? Or is it simply a warning that it could mess with your program? I don't really understand what exactly is being done when you include multiple header files of the same name... >.>

-vexstorm
Last edited on Jan 21, 2009 at 9:54pm
Jan 21, 2009 at 10:25pm
You can try it out, your compiler should stop compiling when it finds a double declaration for the same symbol
Last edited on Jan 21, 2009 at 10:25pm
Jan 21, 2009 at 11:56pm
The compiler will probably (it depends on the actual contents of the header) generate the same error than with this:
1
2
int a;
int a;
Jan 22, 2009 at 12:06am
Actually, with proper include guards, including the same header file twice has no effect. It just takes a little bit longer to compile the code.

Without a header guard, you'd end up with multiple-definition errors on anything declared in the header.
Topic archived. No new replies allowed.