Maximum ID Length

Where can I find the maximum identifier length in C?

In which header file does this limit appear?

+8
c
Feb 28 '10 at 18:58
source share
3 answers

There is no header file to contain an identifier length limit; even if it was, how could it help you? You cannot change the length of the identifier at compile time depending on the value in the header file.

standard C , section 5.2.4.1 states:

  • 63 important leading characters in the internal identifier or macro name (each generic character name or extended source character is considered a single character)
  • 31 significant leading characters in the external identifier (each universal symbol name defining a short identifier 0000FFFF or less is considered 6 characters, each universal symbol name defining a short identifier 00010000 or more is considered 10 characters, and each extended source symbol is considered the same number of characters , as the corresponding universal name of the symbol, if any)

It also contains a footnote:

Implementations should avoid introducing fixed translation restrictions when possible.

So, you should check your documentation to see if your compiler supports more meaningful characters in identifiers.

+21
Feb 28 '10 at 19:01
source share

There is no headline that tells you. You must make an informed decision based on the platforms you are likely to port to. Karl Norum indicated that he says the standard is C99.

Once upon a time, you could only rely on 6 unique characters, monophonic, for external variables - because it was provided by some mainframe environments. (This is what the C89 standard said, but he noted that the restriction was painful.)

These days, partly due to type binding in C ++, you can reasonably rely on much longer names for external characters. If you start to drift above 31 characters, you may run into problems, but you also run into reading problems.

+8
Feb 28 '10 at 19:06
source share

In short, the header file does not exist to tell you that it is part of the standard ANSI / ISO C specifications, which defines the syntax and environment mechanism layout for the C language itself. In the pre C89 standards, the maximum identifier length was 6 due to small sections of memory and environments on systems such as Mainframes and * nix.

Today, the most recent standard is the C99 standards, which specify that the maximum length for an identifier should be 32, the reason is quite simple and logical ... the compiler works by analyzing the input stream, which will be passed as a command line argument, makefile or solution (for Microsoft environments Visual Studio), the parser is rigid and fixed and therefore imposed restrictions on the length of the identifier, so that the parser can look ahead and see if there are more characters. Exactly because of this reason.

Another reason is that most C ++ compilers use a name definition for identifiers, which, as Jonathan Leffler pointed out, can confuse the compiler, as well as the code relationship.

Hope this helps, Regards, Tom.

+3
Feb 28 '10 at 19:38
source share



All Articles