Re:Comparing C and C++ usage and performance with a real wor...
by nly on Sunday September 03, 2017 @02:48PM
(#15163099)
Template instantiation surely only requires type substitution and re-running some analysis though. What makes C++ compilation slow is reparsing headers again and again and again because the C the preprocessor means that every time they are encountered they may have new semantics.
The motivation for modules in C++ is similar to that of developing a Binary AST for Javascript, discussed on HN recently.
Re:Comparing C and C++ usage and performance with a real wor...
by dozzie on Sunday September 03, 2017 @06:25PM
(#15164316)
> What makes C++ compilation slow is reparsing headers again and again and again because the C the preprocessor means that every time they are encountered they may have new semantics.
Really? And I thought that this is why C and C++ headers are typically wrapped in #ifndef-#define-#endif block, so they only produce whitespace after preprocessing on second inclusion.
Re:Comparing C and C++ usage and performance with a real wor...
by Matthias247 on Sunday September 03, 2017 @07:21PM
(#15164548)
Yes, this happens inside a single translation unit (.cpp file). However if you have multiple .cpp files which include the same header file you have to reparse it each time. This is because before the inclusion of that header different #defines might have been set (e.g. through other headers), and therefore the content of the header file might be different.
Re:Comparing C and C++ usage and performance with a real wor...
by astrodust on Sunday September 03, 2017 @07:22PM
(#15164552)
It's not the second inclusion that's a problem but the way any given template might behave completely differently depending on what order they're loaded in.
That is, including a, b, c is not necessarily the same as a, c, b or b, a, c. This is not true with proper modules, they're order invariant, and as such you can make a ton of optimiztions.
Re:Comparing C and C++ usage and performance with a real wor...
by astrodust on Sunday September 03, 2017 @03:07PM
(#15163209)
If modules ever happen, wow, C++ is going to feel like a whole new language. I remember large Pascal codebases compiling in as little time as it took to press the key, and this was in the era of computers with mere megabytes of memory.
Turbo C++ was never as "turbo" as Turbo Pascal.
Re:Comparing C and C++ usage and performance with a real wor...
by fasquoika on Sunday September 03, 2017 @06:48PM
(#15164412)
That's probably not just modules though. Pascal, being one of Niklaus Wirth's languages, was specifically designed to be easy to compile, generally not even requiring building an AST (though a particular compiler still might, especially of it added extensions to the language).
I'm skeptical. Modules don't avoid the need for template instantiation.