Maximum length of statement in C

后端 未结 2 1673
情深已故
情深已故 2021-01-06 00:04

Is there a maximum length for a statement defined in C?

compiler is gcc

2条回答
  •  逝去的感伤
    2021-01-06 00:14

    The standard specifies a minimum translation limit:

    c11

    5.2.4.1 Translation limits

    1 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:

    [...]

    — 4095 characters in a logical source line

    The standard recommends however that "implementations should avoid imposing fixed translation limits whenever possible".

    A logical source line is the result of backslash-newline splicing (5.1.1.2:1.2), so this doesn't directly cover the minimum limit for the number of characters in a statement.

    However, because another translation limit requirement is:

    — 4095 characters in a string literal (after concatenation)

    and as string literals may only occur in statements, it follows that the implementation must accept at least one 4095-character statement.

    Ignoring literals, we also see:

    — 127 arguments in one function call

    and as a function call must include at least 2 characters per argument, plus 4 for the invocation (f(0,0,...);) we arrive at a minimum line length limit of 260.

提交回复
热议问题