Identifiers provide names for the following language elements:
Classes and class members
Templates
Template parameters
NamespacesAn identifier consists of an arbitrary number of letters, digits, or the underscore character in the form:
.------------. V | >>-+-letter-+----+-letter-+-+---------------------------------->< '-_------' +-digit--+ '-_------'
Related information
The first character in an identifier must be a letter or the _ (underscore) character; however, beginning identifiers with an underscore is considered poor programming style.
The compiler distinguishes between uppercase and lowercase letters in identifiers. For example, PROFIT and profit represent different identifiers. If you specify a lowercase a as part of an identifier name, you cannot substitute an uppercase A in its place; you must use the lowercase letter.
The universal character names for letters and digits outside of the basic source character set are allowed in C++ .
Depending on the implementation and compiler
option, other specialized identifiers, such as the dollar sign ($)
or characters in national character sets, may be allowed to appear
in an identifier.
Identifiers with two initial underscores or an initial underscore followed by an uppercase letter are reserved globally for use by the compiler.
Identifiers that begin with a single
underscore are reserved as identifiers with file scope in both the
ordinary and tag namespaces.
Identifiers that begin with a single
underscore are reserved in the global namespace.
Although the names of system calls and library functions are not reserved words if you do not include the appropriate headers, avoid using them as identifiers. Duplication of a predefined name can lead to confusion for the maintainers of your code and can cause errors at link time or run time. If you include a library in a program, be aware of the function names in that library to avoid name duplications. You should always include the appropriate headers when using standard library functions.
The C99 predefined identifier __func__ makes a function name available for use within the function. Immediately following the opening brace of each function definition, __func__ is implicitly declared by the compiler. The resulting behavior is as if the following declaration had been made:
static const char __func__[] = "function-name";
where function-name is the name of the lexically-enclosing function. The function name is not mangled.
The function name is qualified with the enclosing class name or function name. For example, if foo is a member function of class X, the predefined identifier of foo is X::foo. If foo is defined within the body of main, the predefined identifier of foo is main::X::foo.
The names of template functions or member functions reflect the instantiated type. For example, the predefined identifier for the template function foo instantiated with int, template<classT> void foo() is foo<int>.
For debugging purposes, you can explicitly use the __func__ identifier to return the name of the function in which it appears. For example:
#include <stdio.h>
void myfunc(void) {
printf("%s\n",__func__);
printf("size of __func__ = %d\n", sizeof(__func__));
}
int main() {
myfunc();
} The output of the program is:
myfunc size of __func__=7
Related information