Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...