C ++中的标识符名称的长度是否有限制? [英] Is there a limit to the length of identifier names in C++?

查看:2009
本文介绍了C ++中的标识符名称的长度是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中的变量名称是否有长度限制?它是什么?这与机器的64/32位有什么关系?



EDIT:具体来说,GCC的限制是什么? C ++标准的

解决方案

部分 lex.name >


标识符是一个任意长的字母和数字序列。


但是,共享非常大量初始字符的变量名称可能不会被视为单独的变量,所使用的初始字符的确切数量是实现特定的。附件B说:


由于计算机是有限的,C ++实现不可避免地限制了它们可以成功处理的程序的大小。每个实施应记录已知的那些限制。本文档可以引用存在的固定限制,说明如何根据可用资源计算变量限制,或者说固定限制不存在或未知。



限制可以限制包括下面描述的那些或其他的量。推荐每个数量后面的括号数作为该数量的最小值。







对于gcc,限制为:



预处理程序:无限制



C语言:无限制



C ++:可能与C相同,没有单独的限制记录。 某些选项记录在C语言的相应文档中

链接器(控制跨编译单元链接的外部名称):平台特定,通常无限


Is there a length limit to the names of variables in C++? What is it? Does this have anything to do with the "64/32-bitness" of the machine?

EDIT: Specifically, what is GCC's limit?

解决方案

section lex.name of the C++ standard says

An identifier is an arbitrarily long sequence of letters and digits.

However, variable names which share a very large number of initial characters may not be treated as separate variables, the exact number of initial characters used is implementation-specific. Annex B says:

Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known. This documentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

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.


For gcc, the limits are:

Preprocessor: no limit

C language: no limit

C++: Probably same as C, no separate limit documented. "Some choices are documented in the corresponding document for the C language"

Linker (controls external names linked across compilation units): Platform-specific, often unlimited

这篇关于C ++中的标识符名称的长度是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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