What is the exact role of \"significant characters\" in C , especially in the field of variables? I have read the topic “(K&R) At Least the first 31 characters...”, but
There is no role - the number of significant characters is a limitation imposed by C linkers. The 31 char limit was used by early linkers.
In the current C standard, ISO/IEC 9899:2011, section §5.2.4.1 Translation limits says:
The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:18)
...
— 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)19)
...18) Implementations should avoid imposing fixed translation limits whenever possible.
19) See ‘‘future language directions’’ (6.11.3).§6.11.3 External names
¶1 Restriction of the significance of an external name to fewer than 255 characters (considering each universal character name or extended source character as a single character) is an obsolescent feature that is a concession to existing implementations.
This means that when dealing with names, internal names that are distinct within the first 63 characters must be treated as distinct by the compiler, but if you are misguided enough to create two (or more) identifiers that differ in the 64th character only (the first 63 are identical, but the 64th character in one is, say, 1
and in the other is z
), then the compiler may legitimately, and without warning, treat those two identifiers as the same.
The limit on external names — names which affect the linker rather than the compiler proper — may be limited to as few as 31 characters. Consider:
extern int abcdefghijkjlmnopqrstuvwxyz123456;
extern int abcdefghijkjlmnopqrstuvwxyz123457;
These two declarations may be treated as referring to the same variable if the system (linker) limits you to 31 characters.
As the future directions section states, any limit shorter than 255 is 'obsolescent', meaning that you should not be limited by this before names are 255 characters long. But the standard does not mandate 255 characters as the limit yet.
Previous editions of the standard had smaller lower bounds on the upper limits of the lengths of names. The C89 standard only mandated 6 characters monocase for external names (but it was regarded as a painful concession to existing linkers), so strcmp
and StrCmp
could be the same, as could abcdefg
and abcdefz
. Part of the trouble may have been Fortran; it only required support for 6 character monocase names, so linkers on systems where Fortran was widely used did not need to support longer names.
The limits in C99 were the same as in C11.
In the old days of C, when the compilers and programs were run on machines with very limited memory (think kilobytes, not gigabytes) then to save memory the compilers only used up to eight (on the early compilers) characters of identifiers (names of variables, functions etc.). This is the role of "significant characters", it's the number of characters the compiler uses for names in the source.
This is what I think,
It means that all the characters, after first 31 characters will be ignored, i.e. variable names:
ab..(27 characters)..yz123
ab..(27 characters)..yz578
will be treated as:
ab..(27 characters)..yz
and so you can get redeclaration error...