Hacker News new | ask | show | jobs
by thinkling 1147 days ago
I’ve been out of C/C++ development for a long time but seem to remember that precompiled headers were a thing back in the day. That approach didn’t have the name space issues pointed out here. Why are precompiled headers not used anymore?
4 comments

As far as I am aware, they never work that great on UNIX compilers, as no big effort was ever spent improving them.

About 20 years ago, on UNIX workloads we used to speed the compilation via ClearMake, a kind of distributed version of code cache that would plug into the compilers, however it has part of ClearCase SCM product.

On Windows, with Microsoft and Borland (nowadays Embarcadero), they work quite alright.

Also, modules will fix that, as per VC++ reports, importing the whole standard library (import std, as per C++23) takes a fraction of only including iostream.

They are still used in some places. But they have some downsides:

Precompiled headers don't play nicely with distributed compilation or shared build caches (which are perhaps the fastest way to build large C++ codebases). So while they can work well for local builds, they exclude the use of (IMO) better build-time optimisations.

They also require maintenance over time- if you precompile a bad set of headers it can make your compile times worse.

They're very much alive and well on MSVC. Our work projects use both unity builds _and_ precompiled headers.
In a project that already has good header hygiene, precompiled headers don't help much to speed up builds. They're just a bandaid when the situation is already completely out of control.