question? why not #include .. everything )

Started by
6 comments, last by _Madman_ 18 years, 9 months ago
Im sure that it is not recommended but why not just put all your header delarations in one header then just include that header in all your source files for the project.... well assuming you have the proper #pragma once // #ifdef ---- what side effects could this cause.. other than reusability perhaps
Advertisement
Slows down compilation time
It would make it incredibly easy to make all of your program components interdepend on each other. I don't want my SoundManager to know about my Renderer etc.
Now, if a start a new game, I can just pick up my sound code from the previous game and plug it in..
I use #ifdef approach and it's fine for avarage project and good compiler.
______________________________Madman
Each time you change that one header file you'll need to recompile the whole program. For small programs, you woudn't be able to tell a difference. Once programs become larger however, it becomes much more of a problem. Also, it would be a problem if the program is being written by more than one programmer. There are more problems that would probably arise, but these are probably the most prominent. A modular approach is the way to go.
One positive aspect of that though is if you're building a library. Then a single "master" header can be quite handy for the people using your library.
Quote:Original post by abdulla
One positive aspect of that though is if you're building a library. Then a single "master" header can be quite handy for the people using your library.


One external header that exposes your library, perhaps. But for any significant library, there will be many more files internally.

There are two reasons not to do this:
1) As interdependencies between components grow, it can be quite difficult to make the project work. Sometimes, you'll find that a single include file simply can't resolve all of the interdependencies.
2) Compile time. Once you're working with tens of thousands of lines of code (reasonable for a serious hobby project), you do not want to be waiting for the entire thing to recompile because you made an obscure change in one part of the code.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Usually you dont change your header file often, if so, compile times dont grow, as only neded cpp file is compiled/linked.
______________________________Madman

This topic is closed to new replies.

Advertisement