What is max length for an C/C++ identifier on common (build) systems?
- 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?
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)
Annex B of the C++ Standard says that an implementation should support identifiers at least 1024 characters long, but this is not mandatory.