3 ms·
This is not only not true, but not possible. Many kind sof defintiions in .h files may not be repeated without error, like: struct foo { int bar; }; or t
by kazinator 3y ago
This is not only not true, but not possible. Many kind sof defintiions in .h files may not be repeated without error, like:
struct foo { int bar; };
or
typedef int xyzzy_t;
This is why you have include guards:
#ifndef FOO_H_3DF0_755A
#define FOO_H_3DF0_755A
struct foo { int bar; }
#endif
GCC optimized the handling of headers with include guards 30 years ago already.
If you think most of your compile time is spent in preprocessing, benchmark a clean build with the optimization set to -O0 versus your full optimization like -O2 or whatever you are using.
Both builds perform preprocessing; thus the preprocessing time is bounded by the total time spent in the -O0 build: if the actual semantic analysis of tokens and code generation at -O0 were to take next to no time at all, then we would have to attribute the time to tokenizing and preprocessing. But even then, all the additional time observed under -O2 is not tokenizing and preprocessing.
- WalterBright 3y agoUm, I think there is a misunderstanding. gcc -c a.c gcc -c b.c requires reparsing of the .h files used by both.