Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

c++ - Source line length limit

What's the maximum length of a source line all compilers are required to accept? Did it change in C++11? If so, what was the old value?

I'm asking this question because I'm doing some heavy preprocessor voodoo (unfortunately, templates won't cut it), and doing so has a tendency to make the lines big very quickly. I want to stay on the safe side, so I won't have to worry about the possibility of compiler X on platform Y rejecting my code because of too long lines.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

C++2003, Annex B, (informative) Implementation quantities (sorry, don't have C++2011 handy)

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

  • Characters in one logical source line [65 536].

You didn't ask about these, but they might be useful, also:

  • Nesting levels of parenthesized expressions within a full expression [256].
  • Macro identifiers simultaneously defined in one translation unit [65 536].
  • Arguments in one macro invocation [256].
  • Number of characters in an internal identifier or macro name [1 024].
  • Macro identifiers simultaneously defined in one translation unit [65 536].
  • Parameters in one macro definition [256].


Postscript: It is worth noting what "one logical source line" is. A logical source line is what you have after:
  • Physical source file characters are mapped to the basic source character set
  • Trigraph sequences (2.3) are replaced by corresponding single-character internal representations
  • Each instance of a new-line character and an immediately preceding backslash character is deleted

The logical source line is what you have before:

  • The source file is decomposed into preprocessing tokens
  • Preprocessing directives are executed and macro invocations are expanded.

[quotes from C++ 2003, 2.1 Phases of Translation]

So, if the OP's concern is that the macros expand to beyond a reasonable line length, my answer is irrelevant. If the OP's concern is that his source code (after dealing with , ) might be too long, my answer stands.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...