In the C book, it says:
At least the first 31 characters of an internal name are significant. For function names and external variables, the number may be less than 31, because external names may be used by assemblers and loaders over which the language has no control. For external names, the standard guarantees uniqueness only for 6 characters and a single case. Keywords like if, else, int, float, etc., are reserved: you can't use them as variable names. They must be in lower case.
Can someone explain what is "internal name", "external names", "external variables"? It would be better if you can make an example.
Internal variables typically consist of the variables being manipulated and measured. External variables are factors outside the scope of the experiment, such as a participant becoming sick and unable to attend.
"Internal names" are names of identifiers within a function (effectively local variable names). "External names" would be the names of the other identifiers, including the names of functions and any identifiers declared at global scope or declared with storage class extern.
ANSI standard recognizes a length of 31 characters for a variable name. However, the length should not be normally more than any combination of eight alphabets, digits, and underscores. 4. Uppercase and lowercase are significant.
External identifiers are the ones that have to be visible outside the current source code file. Typical examples of these would be library routines or functions which have to be called from several different source files.
Stroking my white beard and speaking in a sage and pompous voice, I say:
In the olden days, when FORTRAN and COBOL ruled the computing world, the upstart language C had to fit in to existing tool chains. Those tool chains included link-editors (a/k/a linkers, a/k/a loaders) and assemblers that only handled short 6-character symbol (variable and function) names.
C compilers for those tool chains had to pretend that variable and function names were short when they wrote out object files to be consumed by the link-editors. That was the bad news. The good news was that there are plenty of symbols inside C programs that don't need to show up in the object files.
For example, the names of functions ... e.g. "main" and "sqrt" ... need to show up in the object modules, so code from other object modules could use them. So did the names of "extern" style global variables. Those are the external names.
But all the other names in a C program, for example the names of variables in the scope of functions, the names of members of structs, and so forth, didn't have to make it into the object modules. Those are called "internal names."
So, for example, you could have these C variables within a function
int myFavoriteItem; int myFavoriteThing;
and that would be fine. But you could declare them as external variables, like so:
extern int myFavoriteItem; extern int myFavoriteThing;
Some systems would write these names out to the object files as if they were six letters long (because the object files didn't know what to do with longer names). They would then look to the object file as if they had been declared like this.
extern int myFavo; extern int myFavo;
Those would be duplicate declarations. The C compiler was required to catch this kind of thing and throw an error, rather than write a duplicate declaration to an object file. That was a great help to programmers: duplicate declarations in object files generated really obscure link-editor error messages.
The passage you quoted specifies that compilers have to recognize at least 31 characters of an internal name and 6 of an external name. Modern compilers and toolchains no longer have different name-length limitations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With