When using precompiled headers, does it make a difference (or has a bad effect) when I include a header, which I already have included in the precompiled header, also in a regular header?
Or in other words: when I include a header x in another header file and at the same time include x in my precompiled header file, does this prevent the optimization provided by precompiled header to kick in?
Precompiled headers allow the compiler to save the result of compiling a group of headers into a PCH file that can be used in place of those header files in subsequent compilations. If you want to learn more, this document talks about the benefits of precompiled headers and how to use them in your projects.
In this case, all include files can be precompiled into one precompiled header. The first compilation — the one that creates the precompiled header (PCH) file — takes a bit longer than subsequent compilations.
When you specify the Use Precompiled Header File (/Yu) option, the compiler ignores all preprocessor directives (including pragmas) that appear in the source code that will be precompiled. The compilation specified by such preprocessor directives must be the same as the compilation used for the Create Precompiled Header File (/Yc) option.
Precompiled headers are supported in GCC (3.4 and newer). GCC's approach is similar to these of VC and compatible compilers. GCC saves precompiled versions of header files using a " .gch " suffix. When compiling a source file, the compiler checks whether this file is present in the same directory and uses it if possible.
(In general). What's going to happen is that, during compilation, if you're using precompiled headers, and the compiler spots a header that is already present in the precompiled form, it will opt to use the precompiled form.
In fact, it's good practice to continue using your includes as if you never had precompiled headers on in the first place. This helps in case you turn off precompiled headers in the future or modify the list of headers in it, or someone else decides to do their own out-of-source build that doesn't use PCH.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With