Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is max length for an C/C++ identifier on common (build) systems?

Tags:

c++

c

limit

People also ask

What is the maximum possible length of an identifier in C?

Why there is a limit on the length of an identifier(31 characters) in C ? The standard only places lower bounds for implementations to follow, probably to ensure lowest common denominator in current architecture. But it also encourages implementations to far exceed them whenever possible.

What is the maximum length of an identifier name?

Answer: An identifier can have a maximum length of 79 characters in Python. Python is one of the most popular programming languages.

What is the maximum length of an identifier in C Plus Plus?

Only the first 2048 characters of Microsoft C++ identifiers are significant. Names for user-defined types are "decorated" by the compiler to preserve type information. The resultant name, including the type information, cannot be longer than 2048 characters.

Can an identifier be of any length?

Identifiers can be of any length and can consist of letters, numbers, and underscores. Identifiers cannot begin with a digit. In PHP, identifiers are case sensitive.


  • Microsoft C++: 2048 characters
  • Intel C++: 2048 characters
  • g++: No limit, as answered in this question: is there a length limit on g++ variable names?

Annex B of the C++ Standard says that an implementation should support identifiers at least 1024 characters long, but this is not mandatory.


Based on MISRA C 2004:

Rule 5.1 (required): Identifiers (internal and external) shall not rely on the significance of more than 31 characters. [Undefined 7; Implementation 5, 6] The ISO standard requires internal identifiers to be distinct in the first 31 characters to guarantee code portability. This limitation shall not be exceeded, even if the compiler supports it. This rule shall apply across all name spaces. Macro names are also included and the 31 character limit applies before and after substitution. The ISO standard requires external identifiers to be distinct in the first 6 characters, regardless of case, to guarantee optimal portability. However this limitation is particularly severe and is considered unnecessary. The intent of this rule is to sanction a relaxation of the ISO requirement to a degree commensurate with modern environments and it shall be confirmed that 31 character/ case significance is supported by the implementation. Note that there is a related issue with using identifier names that differ by only one or a few characters, especially if the identifier names are long. The problem is heightened if the differences are in easily mis-read characters like 1 (one) and l (lower case L), 0 and O, 2 and Z, 5 and S, or n and h. It is recommended to ensure that identifier names are always easily visually distinguishable. Specific guidelines on this issue could be placed in the style guidelines (see section 4.2.2).

I use this rule. Maybe somebody asks me "Do you see any compiler that can't recognize identifier more than 31?" Yes, I remember in IAR RL78 v2.21.1 I defined 2 identifier without any warning and error, but I faced problem in access(now I don't remember what was the exact scenario)