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?
The following table describes the maximum length for each type of identifier. Aliases for column names in CREATE VIEW statements are checked against the maximum column length of 64 characters (not the maximum alias length of 256 characters).
ANSI standard recognizes a length of 31 characters for a variable name. However, the length should not be normally more than any combination of eight alphabets, digits, and underscores. 4. Uppercase and lowercase are significant.
65535 bytes in an object (in a hosted environment only)
The length of the identifiers should not be more than 31 characters. Identifiers should be written in such a way that it is meaningful, short, and easy to read.
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
In MS Visual Studio 2003–2012 the maximum length of an identifier is 2047 characters (per MSDN).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With