Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 957
TemplateRex Avatar asked Aug 25 '12 19:08

TemplateRex


People also ask

What is the standard for where you include the header?

The “#include” preprocessing directive is used to include the header files with “. h” extension in the program. Here is the table that displays some of the header files in C language, Sr.No.

Should includes go in header?

Your #include s should be of header files, and each file (source or header) should #include the header files it needs. Header files should #include the minimum header files necessary, and source files should also, though it's not as important for source files.

Is it possible to have nested include files in C?

Include files can be nested: An #include directive can appear in a file that's named by another #include directive.

Do you put include statements in header files?

You make the declarations in a header file, then use the #include directive in every . cpp file or other header file that requires that declaration. The #include directive inserts a copy of the header file directly into the . cpp file prior to compilation.


2 Answers

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).

like image 98
Jaxan Avatar answered Oct 03 '22 21:10

Jaxan


I wrote a header file that includes itself and compiled it with MSVS 2010. That gave the error message:

fatal error C1014: too many include files : depth = 1024
like image 42
Johan Råde Avatar answered Oct 03 '22 21:10

Johan Råde