Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precompiled headers and normal includes

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?

like image 992
Mike Lischke Avatar asked Jan 12 '17 13:01

Mike Lischke


People also ask

What are precompiled headers?

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.

Can all include files be precompiled into one header?

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.

What is the difference between create precompiled header file (/Yu) and (/YC)?

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.

Does GCC support precompiled headers?

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.


1 Answers

No

(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.

like image 192
AndyG Avatar answered Dec 03 '22 23:12

AndyG