4 ms·
>> No you didn't, because header files have header guards of the form #ifndef HEADER_GUARD/#define HEADER_GUARD or #pragma once which means that header files ar
by phkahler 5y ago
>> No you didn't, because header files have header guards of the form #ifndef HEADER_GUARD/#define HEADER_GUARD or #pragma once which means that header files are only parsed the first time they are included.
The header file still as to be read from disk ignoring everything until #end and then continue. This is probably not much of an issue these days with SSDs and even HDDs with caches.
I think the rule can still be a good thing by making you aware of what the dependencies actually are, which can be an indicator of excess complexity or poorly defined interfaces.
- Kranar 5y agoLoading the same file from disk twice (which will be cached in memory) and parsing a file are not the same things. Furthermore almost every C++ compiler I'm aware of, including icc, gcc, clang, msvc, has optimizations to special case header guards.
- ncmncm 5y agoEvery C++ compiler still in use will not even try to open a header-guarded or #pragma once file it has already seen. Anybody trying to optimize on top of that is engaged in foolish superstition. (If you are still using Sun's pre-Standard compiler, you are not reading this. I think even Bloomberg has abandoned that.)
- kevin_thibedeau 5y agoIt doesn't have to be read twice if the preprocessor recognizes and keeps track of include guards. GCC does this.