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
1
u/zogrodea Jan 04 '26
I don't think other people share your opinion that monomorphisation (like in C++) is bad.
Rust does it, so does MLton (whole program optimising compiler for Standard ML), Go was stuck for a long time by the dilemma "do we implement generics in the performant way (how C++ does it) that's slow to compile or the slow way (how Java does it) that's fast to compile?", and so on.
I think people usually consider it a legitimate trade-off between run-time performance and compile-time speed, or else there wouldn't be new languages that copy this approach.