3 ms·
> 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
by dozzie 9y ago
> 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.
- Matthias247 9y agoYes, 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.
- astrodust 9y agoIt'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.