top | item 46928016

(no title)

petters | 22 days ago

> C++ doesn't take longer to compile if you don't abuse templates.

Surprisingly, this is not true. I've written a C++ file only to realize at the end that I did not use any C++ features. Renaming the file to .c halved the compilation time.

discuss

order

levodelellis|22 days ago

I don't believe you, I measured compile times in c compilers and my own. If you provide more information I'd be more likely to believe you

flohofwoe|21 days ago

On some compiler toolchains (IIRC MSVC was the main offender) you get a lot more code pulled into your source file when including a C stdlib header (like <stdio.h>) in C++ mode versus C mode. Basically a couple hundred lines in C mode versus thousands of lines in C++ mode.

petters|21 days ago

That's fair. I'm unable to provide more information though so we'll have to disagree.

levodelellis|22 days ago

[deleted]

jsheard|22 days ago

I agree it shouldn't really matter if there's no C++ features in play, but I suppose third party headers could bite you if they use #ifdef __cplusplus to guard optional C++ extensions on top of their basic C interface. In that case the compiler could be dealing with dramatically more complex code when you build in C++ mode.