Sign in to follow this  
jchmack

Is this practical

Recommended Posts

Whenever i start a new project i use a linker.h file that just includes all of the files im gonna use then just include it in all my other files. Does this have any unseen drawbacks? I noticed alot of the code i read doesn't do this. i use #ifndef and #define to prevent double inclusion. I was thinking it might shoot up compile times or something. Well just curious =)

Share this post


Link to post
Share on other sites
Yep, if you use that scheme you soon will have 10 minute compile times for every change you make to any header file.

Share this post


Link to post
Share on other sites
when you write a project in many files you want to compile the minimum neccessary files and link the results.
The program "make" is used (or something similar) which uses a makefile (or something similar) to decide which files have changed. It does so by looking at the date of the file and the files it is dependant on.
If you are using IDE (such as visual studio) then this is hidden from you, but it works the same.
By including every header in every source you make every source dependant on every header. Changing one header will make the date new and every source file will be recompiled, many of them for no reason.

If you include only the needed headers then changing header file will recompile only the sources that use it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Trap
Yep, if you use that scheme you soon will have 10 minute compile times for every change you make to any header file.


Trap, do you remember the time when you had to (only schematically):

#include <Direct3dSurface.h>
#include <Direct3dTexture.h>
#include <Direct3dDevice.h>
#include <Direct3dInlineFuncs.h>
...
...
...

well, I don't. I always did only this one:

#include <Direct3d.h>



You have to consider that a change to a header is always something you have to think about, since the .h-files contain type definitions which the .c/.cpp-files depend on.
jchmack, you're doing right if you put some small files together that way. It helps you to always include the headers in the correct order.

Share this post


Link to post
Share on other sites
It's common to do something like this with header files that don't or very rarely change. It's generally a bad idea to do it with all of your header files, including those in the project that can and do change at any time.

Share this post


Link to post
Share on other sites
Yeah, correct, one shouldn't make a <all-in-one-because-I-am-lazy.h>.

What my statement was for: Consider you develop your game in mainly two parts, the one part the game itself, the other one the graphics engine. There should be as few includes for the graphics engine files as possible (okay, thats my opinion. maybe you like to include every single component on demand. but have a look at the project-file-tree of my root-engine, and then ask yourself: Do I really want to include 5 files or so just because I wanna use the terrain engine?).

If there are just a few tool-like headers like <3dmath.h>, <intersections.h> or <parseFunctions.h> I would also prefer to include them on demand.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this