Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting precompiled headers

Is there a way for the preprocessor to detect if the code in current translation unit uses(or is creating) precompiled headers?

---
The actual problem I'm facing right now is that I'm on a project that is abusing PCH by precompiling virtually all header files.
That means there is none of the clear dependency management you can get from #includes and the compile times is awful. Practically every change will trigger a full rebuild.
The application is way to big to just fix it in one go, and some of the old guys refuses to belive that precompiling everyting is bad in any way. I will have to prove it first.
So I must do it step by step and make sure my changes does not affect code that is compiled the old PCH way.
My plan is to do ifdef out the PCH.h and work on the non PCH version whenever I have some time to spare.

#ifdef USES_PCH
#include "PCH.h"
#elif
// include only whats needed
#endif

I would like to avoid defining USES_PCH at command line and manually keep it in sync with /Y that, besides from not being very elegant, would be a pain. There is a lot of configurations and modules to juggle with and a lot of files that don't follow project defaults.

like image 923
grimner Avatar asked Aug 25 '09 08:08

grimner


People also ask

Where do I find precompiled headers?

In the project property pages, the options are located under Configuration Properties > C/C++ > Precompiled Headers.

Why do I get precompiled headers?

Usage of precompiled headers may significantly reduce compilation time, especially when applied to large header files, header files that include many other header files, or header files that are included in many translation units.

How do I not use precompiled headers?

To turn off precompiled headersSelect the Configuration properties > C/C++ > Precompiled Headers property page. In the property list, select the drop-down for the Precompiled Header property, and then choose Not Using Precompiled Headers.

How do you make a precompiled header?

To make builds faster, GCC allows users to `precompile' a header file; then, if builds can use the precompiled header file they will be much faster. To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file.


1 Answers

If Visual C++ defined a constant to indicate whether precompiled headers were in use, it would probably be listed in Predefined Macros. And it's not documented there, so it probably doesn't exist. (If it does exist, it's probably undocumented and may change in a future version.)

like image 154
bk1e Avatar answered Sep 24 '22 04:09

bk1e