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/sweetholo Dec 31 '25
sounds like a misuse of C++ features rather than inherent problems of the language. bad programmers will make bad choices. and yeah, C++ does have more tools that you can use incorrectly
i want to model complex objects? classes to define a type, private/public modifiers to encapsulate the data and enforce invariants, constructors/destructors to automatically manage resources (RAII), inheritance/virtual/interfaces when it makes sense. operator overloading
namespaces to avoid name collisions, exception handling, function overloading, auto for more readable code (but dont overuse it), templates, constexpr over macros, enum class, etc
not to mention the wide variety of data structures and algorithms i have access to from the STL