Why are some C++ names short and sometimes hard to understand like strcmp
,
cout
, cin
, etc. But in other languages like Java name are not short. Does it save time, memory or what?
Although ANSI allows 6 significant characters in external identifier names and 31 for names of internal (within a function) identifiers, the Microsoft C compiler allows 247 characters in an internal or external identifier name.
C identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions, labels, etc. An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore.
Identifier refers to name given to entities such as variables, functions, structures etc. Identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of the program.
The rules for the construction of identifiers are simple: you may use the 52 upper and lower case alphabetic characters, the 10 digits and finally the underscore ' _ ', which is considered to be an alphabetic character for this purpose.
This primarily applies to the portions of the standard C++ library that have been "inherited" from C. In pre-C89 standards of the C language the significant portion of external identifiers has been limited to 6 characters; linkers were allowed to ignore the remaining characters. That is why the standard C library limited identifier length to 6 characters. C++ incorporated that library "wholesale", along with somewhat cryptic identifiers.
There are parts of the C++ Standard libraries that are derived from the older C Standard Library. The older C Standard Library in turn was derived from the older K&R library that provided some of the basic functionality through functions which in other languages are built into the language such as Input/Output.
This section of the book Rationale for the ANSI C Programming Language provides a description of the naming conventions for C identifiers.
The C programming language is compiled and the machine code output of the compiler is linked together into the actual applications. The software that does the linking is typically part of the standard tools offered by an operating system vendor. A survey of the available linker applications offered by various vendors found that the most basic provided six characters for the external identifiers that could be processed by the linkers. Some linkers allowed more however by specifying a limit of six characters, the list of available target computers for C compilers was much larger.
By staying with the limits of the linkers, it allowed C programmers to write C programs and function libraries that could be used with software written in other languages as well as allowed the use of libraries written in other languages to be used by C programmers.
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