c++nestedlimitheader-files

Are there limits to how deep nesting of header inclusion can go?


I can't find anything on MSDN or elsewhere, but are there hard-coded limits to how deep nesting of header inclusion can go? Example:

// H1.h
// guards etc.
#include "H2.h"

// H2.h
// guards etc.
#include "H3.h"

//...

// HN.h <---- how large can N get??

I wonder if there is anything in the Standard about this. If the answer is implementation defined, then I'm primarily interested in the Visual Studio toolchain.


Solution

  • The standard also says something about it (in the part about implementation quantities, annex B):

    The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance.

    ...

    • Nesting levels for #include files [256].

    Note that this is only a recommended minimum, so a compiler may not support that many inclusions (but most compilers do, as shown in other answers).