加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C/C++控制结构限制?

发布时间:2020-12-16 10:54:16 所属栏目:百科 来源:网络整理
导读:我听说VC(不确定哪个版本)对嵌套if语句的数量有限制(在300的球场中).代码的形式如下: if (a) ...else if (b) ...else if (c) ...... 我很惊讶地发现这种事情是有限制的,并且限制是如此之小.我不是在寻找关于编码实践的评论以及为什么要完全避免这种事情. 以
我听说VC(不确定哪个版本)对嵌套if语句的数量有限制(在300的球场中).代码的形式如下:

if (a) ...
else if (b) ...
else if (c) ...
...

我很惊讶地发现这种事情是有限制的,并且限制是如此之小.我不是在寻找关于编码实践的评论以及为什么要完全避免这种事情.

以下是我认为可能有一些限制的事项列表:

>作用域中的函数数(全局,类或命名空间).
>单个语句中的表达式数(例如,复合条件).
>交换机中的病例数.
>函数的参数数量.
>单个层次结构中的类数(继承或包含).

还有哪些其他控制结构/语言功能有这样的限制?语言标准是否说明了这些限制(可能是实现的最低要求)?有没有人遇到特定编译器/实现的特定语言限制?

编辑:请注意,if语句的上述形式确实是“嵌套”.它相当于:

if (a) { //...
}
else {
    if (b) { //...
    }
    else {
        if (c) { //...
        }
        else { //...
        }
    }
}

解决方法

Visual C++ Compiler Limits

The C++ standard recommends limits for
various language constructs. The
following is a list of constructs
where the Visual C++ compiler does not
implement the recommended limits. The
first number is the recommended limit
and the second number is the limit
implemented by Visual C++:

  • Nesting levels of compound statements,
    iteration control structures,and
    selection control structures [256]
    (256).

  • Parameters in one macro definition
    [256] (127).

  • Arguments in one macro invocation
    [256] (127).

  • Characters in a character string
    literal or wide string literal (after
    concatenation) [65536] (65535).

  • Levels of nested class,structure,or
    union definitions in a single
    struct-declaration-list [256] (16).

  • Member initializers in a constructor
    definition [6144] (approximately 600,
    memory dependent,can increase with
    the /Zm compiler option).

  • Scope qualifications of one identifier
    [256] (127).

  • Nested external specifications [1024]
    (10).

  • Template arguments in a template declaration [1024] (64).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读