Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max identifier length

Tags:

c

Where can I find what is the maximum identifier length in C?

In which header file is that limit specified?

like image 384
Devel Avatar asked Feb 28 '10 18:02

Devel


2 Answers

There is no header file to contain the identifier length limit; even if there were, how could it help you? You can't change your identifier lengths at compile time based on a value in a header file anyway.

The C standard, section 5.2.4.1 says:

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

It also contains a footnote:

Implementations should avoid imposing fixed translation limits whenever possible.

So you should check your documentation to see if your compiler supports a greater number of significant characters in identifiers.

like image 76
Carl Norum Avatar answered Sep 24 '22 01:09

Carl Norum


There is no header that tells you. You have to make an informed decision based on the platforms to which you are likely to be porting. Carl Norum pointed out what the C99 standard says.

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

These days, in part because of type-safe linkage in C++, you can reasonably rely on much longer names for external symbols. If you start drifting above 31 characters, you may run into problems - but you are also running into readability problems too.

like image 44
Jonathan Leffler Avatar answered Sep 25 '22 01:09

Jonathan Leffler