Let me start by defining what is usually called "external include-guards". Suppose you have a header file called someheader.h
and a code file called source.cpp
. You can have the traditional include-guards inside someheader.h
:
//someheader.h
#ifndef _SOMEHEADER_H_
#define _SOMEHEADER_H_
// ...
#endif // _SOMEHEADER_H_
In the past, I have heard and read multiple times that in really large projects, it would be better for the compiling performance to also have external include guards. which means:
//source.cpp
#ifndef _SOMEHEADER_H_
#include "someheader.h"
#endif
// ...
I guess the reason for such an advice is that with the checking for whether someheader.h
had already been processed happening inside source.cpp
, the compiler could entirely avoid having to search for someheader.h
, open it and just then do the checking. That would be particularly useful in big projects with many levels of nested header inclusions.
Is such an optimization for compiling-times still relevant nowadays, with compilers gcc and visual studio being a lot more well developed?