3 ms·
#include is literally expanded to the contents of the file you are including. And that works recursively until the compiler has one giant source file that recur
by humanrebar 10y ago
#include is literally expanded to the contents of the file you are including. And that works recursively until the compiler has one giant source file that recursively includes the text in all the headers you included. And in that process all preprocessor macros are also expanded. This happens for every source file that is compiled. It would be nice to skip all that and just have some standard way of listing the already-analyzed contents of a the modules you need.
In addition to the obvious performance improvements this would give compilers, this really cuts down on the complexity that third-party tools need to deal with to work well with C++ code. The quality of tooling for C++ has historically been stymied by the complexity of analyzing the code itself. Modules are a huge step in the right direction for helping with this.
- pg314 10y agoAs an illustration of how much code gets included (on macOS Sierra): $ echo "#include <iostream>" > foo.cpp $ g++ -E foo.cpp | wc 37799 104779 1280834 Including just iostream in a file means the compiler has to process 37799 (!) lines. For comparison, a C file including stdio: $ echo "#include <stdio.h>" | gcc -E - | wc 456 1638 20880 That still looks bloated to me, but is about 60x times fewer bytes.
- stirner 10y ago$ curl https://git.musl-libc.org/cgit/musl/plain/include/stdio.h | wc 203 630 5231