Tuesday, September 21, 2010

Identifier Names

In C/C++, the names of variables, functions, labels, and various other user-defined
objects are called identifiers. These identifiers can vary from one to several characters.
The first character must be a letter or an underscore, and subsequent characters must
be either letters, digits, or underscores. Here are some correct and incorrect identifier
names:
Correct             Incorrect
Count                  1count
test23                  hi!there
high_balance     high...balance

In C, identifiers may be of any length. However, not all characters will necessarily
be significant. If the identifier will be involved in an external link process, then at
least the first six characters will be significant. These identifiers, called external names,
include function names and global variables that are shared between files. If the
identifier is not used in an external link process, then at least the first 31 characters
will be significant. This type of identifier is called an internal name and includes the
names of local variables, for example. In C++, there is no limit to the length of an
identifier, and at least the first 1,024 characters are significant. This difference may
be important if you are converting a program from C to C++.
In an identifier, upper- and lowercase are treated as distinct. Hence, count, Count,
and COUNT are three separate identifiers.
An identifier cannot be the same as a C or C++ keyword, and should not have the
same name as functions that are in the C or C++ library.

No comments:

Post a Comment