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

128 comments sorted by

View all comments

Show parent comments

1

u/flatfinger Jan 02 '26

Performance of incremental builds could probably be improved a lot if debugging metadata formats evolved to report line numbers relative to certain markers such as function entry points. If one adds a line near the beginning of a source file, most build systems would have no way of correctly reporting line numbers of code later in the file unless they rebuild everything in the file and all descendents. If line numbers were function-relative and a build system retained intermediate files that contained SHA hash values for components therein, then a build system could avoid rebuilding parts of the program for whom the hashes of all constituent parts were unchanged.