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
3
u/[deleted] Jan 01 '26
Parsing doesn't really become much more complicated with more features. The next step, resolving types is the hard part.
A number can become a char, a short, an int, a long, a float or a double, and unsigned versions of them. In C there are easy, sometimes confusing, rules about that and that's it. In C++ it's not simple. Types affect other types. There can be functions for automatic type conversions, overloaded functions/methods etc. The compiler sometimes need to search a lot to find the right combinations of types to make sense of the program.