Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why some identifiers in the standard C++ library are short?

Tags:

c++

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?

like image 928
fish_shoes Avatar asked Jun 30 '13 04:06

fish_shoes


People also ask

HOW LONG CAN identifiers be in C?

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.

What is standard identifier in C?

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.

Why identifiers are used in C programming?

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.

What is the length of identifier for simple?

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.


2 Answers

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.

like image 54
Sergey Kalinichenko Avatar answered Sep 24 '22 20:09

Sergey Kalinichenko


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.

like image 39
Richard Chambers Avatar answered Sep 24 '22 20:09

Richard Chambers