What is max length for an C/C++ identifier on com

2019-03-14 08:42发布

问题:

I don't remember the standard saying something of the max length for identifiers so in theory they can be long. In real life, those names could be limited by at least the compiler and linker implementations.

While this should work on all systems

int a;

this snippet

#!/usr/bin/perl
print "int" . "b" x 2**16 . ";";

creates a declarationen that gives undefined reference to std::somethings with ld while compiling/linking (using gcc/mingw).

So what are the size limits for an identifier on different systems?

回答1:

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


回答2:

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



标签: c++ limit