头文件包含的深度嵌套有多大的限制? [英] Are there limits to how deep nesting of header inclusion can go?

查看:234
本文介绍了头文件包含的深度嵌套有多大的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MSDN或其他地方找不到任何东西,但是对于头包含的深度嵌套可以进行多大程度有硬编码的限制吗?示例:

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??

我想知道标准中是否对此有任何规定.如果答案是由实现定义的,那么我主要对Visual Studio工具链感兴趣.

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.

推荐答案

该标准也对此做了一些说明(在有关实现数量的部分中,附件B):

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.

...

  • #include文件的嵌套级别[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).

这篇关于头文件包含的深度嵌套有多大的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆