Reputation: 30035
I suppose this is a question about style rather than correctness.
Using visual studio 2012 I find that my project builds very much faster using precompiled headers for windows.h, direct3d11, atlbase, and any standard c++ header files than if I don't use them. The project is heavily using windows so there is no need at all for anything to be portable to other operating systems or compilers for this project.
My question is really should I also include the header files used after the #include "Precomp.h"
. They won't do anything of course as they have header guards or #pragma once but they will help document the dependencies.
What about in .h files? I can't include the precompiled headers in there but in order to make the .h files self contained I always include for example if it uses anything from there. But this is unnecessary because the .cpp file including this .h file will always include the "Precomp.h" file before the .h file that uses it.
So this isn't really about correctness, it's about what's best style for understanding and maintainability.
What is "best practice" in this situation for precompiled headers?
Upvotes: 4
Views: 1297
Reputation: 941545
The rule of thumb is pretty simple: use only headers that never change. So you only get the slow compile once and never again.
Which makes the SDK and compiler headers an easy choice. Your own headers, not so much. Then rule of thumb number two applies: do you have your own headers that should be #included everywhere? And are they actually big enough to make a noticeable speed difference? That's almost always two strikes against, hopefully anyway.
Upvotes: 1