2 ms·
Microsoft's compiler has an optimization that means it doesn't even open the header file a second time if the include guard surrounded all non-comment tokens. I
by spatulon 6y ago
Microsoft's compiler has an optimization that means it doesn't even open the header file a second time if the include guard surrounded all non-comment tokens. I imagine gcc and clang do something similar.
Of course, they also recommend using "#pragma once" unless you're really concerned about portability.
Source: https://docs.microsoft.com/en-us/cpp/preprocessor/once?view=vs-2019 https://docs.microsoft.com/en-us/cpp/preprocessor/once?view=...
> The compiler recognizes the include guard idiom, and implements the multiple-include optimization the same way as the #pragma once directive if no non-comment code or preprocessor directive comes before or after the standard form of the idiom:
- coliveira 6y agoThis is all nice, but not portable. C++ has no formal concept of a "builder", every new invocation of the compiler is independent, so it doesn't know how a previous invocation parsed a particular header file.