源线长度限制 [英] Source line length limit

查看:60
本文介绍了源线长度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有编译器需要 接受的源代码行的最大长度是多少?它在C ++ 11中改变了吗?如果是这样,那么旧值是什么?

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?

我问这个问题是因为我正在做一些沉重的预处理器伏都教(不幸的是,模板不会削减它),这样做有使线条迅速变大的趋势。我想保持安全,所以我不必担心平台Y上的编译器X由于行太长而拒绝我的代码的可能性。

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.

推荐答案

C ++ 2003,附件B,(仅供参考)
实现数量
(对不起,没有C ++ 2011方便)

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


2)限制可能会限制包括以下内容或其他内容的数量。建议将每个数量后面的方括号
作为该数量的最小值。但是,这些数量仅是
的准则,并不能确定合规性。

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.

...


  • 一个逻辑源代码行中的字符[65 536]。

您没有可以问这些问题,但它们可能也有用:

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



  • 完整括号内的嵌套表达式嵌套级别表达式[256]。

  • 在一个翻译单元中同时定义的宏标识符[65 536]。

  • 在一个宏调用中的参数[256]。 / li>
  • 内部标识符或宏名称[1 024]中的字符数。

  • 同时在一个转换单元[65 536]中定义的宏标识符。 / li>
  • 一个宏定义中的参数[256]。

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



  • 物理源文件字符映射到基本源
    字符集

  • 三字组合
    序列(2.3)被相应的单字符内部表示代替
  • 删除换行符和紧接反斜杠字符的每个实例

逻辑源代码行是之前的内容:

The logical source line is what you have before:



  • 源文件被分解为预处理令牌

  • 执行预处理指令并扩展宏调用。

[引自 C ++ 2003,2.1 翻译阶段 ]

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

因此,如果OP关心的是宏扩展到超出合理的行长,我的答案是敌对的。如果OP担心他的源代码(在处理 \ \n 之后) ,我的回答是正确的。

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 \, \n) might be too long, my answer stands.

这篇关于源线长度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆