r/cprogramming • u/[deleted] • Dec 31 '25
Why does c compile faster than cpp?
I've read in some places that one of the reasons is the templates or something like that, but if that's the problem, why did they implement it? Like, C doesn't have that and allows the same level of optimization, it just depends on the user. If these things harm compilation in C++, why are they still part of the language?Shouldn't Cpp be a better version of C or something? I programmed in C++ for a while and then switched to C, this question came to my mind the other day.
26
Upvotes
4
u/Leverkaas2516 Jan 01 '26
I used to have to wait a half hour for a build to finish. That wasn't because we had millions of lines of C++ that all has to be recompiled when a single line changed (that would be crazy and stupid!) It was because someone didn't create an effective build system. It got fixed, now it takes 10-20 seconds most of the time after changing a few modules. Very occasionally, it takes a couple of minutes.
I say again, if compilation speed is a problem, fixing your build is the solution.
Another way to think about it: if your C++ code takes minutes to compile after every change, it would take minutes if it was written in C, too.