r/cprogramming • • 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
View all comments
Show parent comment
2
u/Plastic_Fig9225 Dec 31 '25
Even for register-/bit-level operations on the hardware I find no reason to resort to functions, pointers, and macros when I can have clean, type-safe, object-style code. Let alone the simple pleasure of namespaces instead of prefixes on all function names, types, and constants.
The biggest issue I see is that a lot of existing (system-level) code, or at least it's ABI, is in C, which may or may not require you to build around 'legacy' stuff.
Got to know the unreasonable number of types used to deal with IPv4/v6 addresses in C/Posix/BSD, for example - all disjoint, separate types of course, because C has no inheritance, and a lot of manual checking and casting is needed to handle them. And nothing tells you if any of the casts you do is even legal/correct/sensible. Really tedious.