c - 我的 C 书中的神奇数字 127

标签 c for-loop c99 nested

<分区>

Possible Duplicate:
What limits the number of nested loops in c?

你好。

当我读我的C书时,它说

Nesting for-Loop in C can continue even further up to 127 levels!

127是怎么来的?

我的书没有提到这个。对我来说就像一个神奇的数字。

[更新]

int main()
{
    int number, n, triangularNumber, counter;

    triangularNumber = 0;

    for (counter = 1; counter <= 5; ++counter){
        printf("What triangular number do you want? \n");

        // using a routine called scanf
        scanf("%i", &number);


        triangularNumber = 0;

        for (n =1 ; n <= number; ++n)

            triangularNumber += n;

        printf("Triangular number %i is %i\n", number, triangularNumber);
    }
    return 0;
}

最佳答案

这个数字来自 ISO C 标准,ISO/IEC 9899:1999 :

5.2.4.1 Translation limits

The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:

  • 127 nesting levels of blocks
  • 63 nesting levels of conditional inclusion
  • 12 pointer, array, and function declarators (in any combinations) modifying an arithmetic, structure, union, or incomplete type in a declaration
  • 63 nesting levels of parenthesized declarators within a full declarator
  • 63 nesting levels of parenthesized expressions within a full expression
  • 63 significant initial characters in an internal identifier or a macro name (each universal character name or extended source character is considered a single character)
  • 31 significant initial characters in an external identifier (each universal character name specifying a short identifier of 0000FFFF or less is considered 6 characters, each universal character name specifying a short identifier of 00010000 or more is considered 10 characters, and each extended source character is considered the same number of characters as the corresponding universal character name, if any)
  • 4095 external identifiers in one translation unit
  • 511 identifiers with block scope declared in one block
  • 4095 macro identifiers simultaneously defined in one preprocessing translation unit
  • 127 parameters in one function definition
  • 127 arguments in one function call
  • 127 parameters in one macro definition
  • 127 arguments in one macro invocation
  • 4095 characters in a logical source line
  • 4095 characters in a character string literal or wide string literal (after concatenation)
  • 65535 bytes in an object (in a hosted environment only)
  • 15 nesting levels for #included files
  • 1023 case labels for a switch statement (excluding those for any nested switch statements)
  • 1023 members in a single structure or union
  • 1023 enumeration constants in a single enumeration
  • 63 levels of nested structure or union definitions in a single struct-declaration-list

这些是符合标准的 C 编译器必须能够处理的最小值。

关于c - 我的 C 书中的神奇数字 127,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4847396/

相关文章:

c++ - "for (const auto &s : strs) {} "是什么意思?

c - 我声明了一些其他结构变量,这些变量正在工作,但是这个语句显示

c++ - 我应该使用 C(99) boolean 值吗? (还有 C++ 中的 C++ boolean 值?)

我可以在此函数中使用 restrict 限定符吗?

c - 解释 proc/<pid>/maps 输出的不同行

c - fork() 返回值错误

c++ - 如何在 rich edit 控件中实现对 URL 的鼠标单击

c - 这是 C 中的有效宏吗?

c++ - 在 C++ 中嵌套 for()

c++ - for loop iteration_expression 值在循环退出时不递增