OiO.lk English C# Translation limits of an identifier in C
C#

Translation limits of an identifier in C


I have started to write my own C compiler for the purpose of education. My goal is to be mostly C99 standard conform. Now I have a question about the maximum length of an identifier.

This is an extract from the C99 specification about the identifiers length:

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

C99 (N1256) Section 5.2.4.1

As I understand correct, the maximal length is 63 characters for local identifier (local variable names or static function names) and 31 characters for externally identifiers. If I’m totally wrong please correct me.

On another page from the standard I have read following:

An identifier is a sequence of nondigit characters (including the underscore _, the lowercase and uppercase Latin letters, and other characters) and digits, which designates one or more entities as described in 6.2.1. Lowercase and uppercase letters are distinct. There is no specific limit on the maximum length of an identifier.

C99 (N1256) Section 6.4.2.1

I have marked my misunderstood sentence.

Please can somebody clarify the real limits of an identifier? Because in one text passage there is a limit, in the other text passage not really.

There exists two similar questions on SO:
limit on the length of an identifier in C
Maximum length of identifiers in Turbo C++ and Dev-C++ for both C and C++ languages

Currently I don’t know which limits are useful. I also don’t tried with GCC (as example) if there is a soft limit of 31 or 63 characters if the compiler flag -std=c99 is set.



You need to sign in to view this answers

Exit mobile version