Classes and class members
Templates
Template parameters
NamespacesThe 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++ and at the
C99 language level.
In C++, you
must compile with the -qlanglvl=ucs option
for universal character name support.
The
dollar sign can appear in identifier names when compiled using the -qdollar compiler
option or at one of the extended language levels that encompasses
this option.
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.
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
When the assert macro is used inside a function definition, the macro adds the name of the enclosing function on the standard error stream.
The compiler binds each non-static external variable and function name in the source code to a name that it generates in the object file and any assembly code that is emitted. For compatibility with GCC, the compiler implements an extension to standard C and C++ that allows you to specify the name to be used in the object file and assembly code, by applying an assembly label to the declaration of a global variable or function prototype. You can also define names that do not start with an underscore even on systems where an underscore is normally prepended to the name of a function or variable.
You can use assembly
labels with member functions, and functions and variables that are
declared in namespaces other than the global namespace.
Assembly label syntax >>-declarator--+-asm-----+--(--"--string_literal--"--)----------> +-__asm__-+ '-__asm---' >--+-------------+--------------------------------------------->< '-initializer-'
The string_literal is a valid assembly name that is to be bound to the given object or function. For a label applied to a function declaration, the name must specify an existing function that is defined in any compilation unit; if no definition is available, a link-time error will occur. For a label applied to a variable declaration, no other definition is required.
void func3() __asm__("foo3");
int i __asm("abc");
char c asm("abcs") = 'a';
To
distinguish between overloaded functions, XL C++ mangles function
names in the object file. Therefore, if you use an assembly label
to map a function name, you must use the mangled name of the target
function. Furthermore, you must ensure that an assembly label name
that you specify for a variable does not conflict with any mangled
name. Alternatively, you can prevent name mangling on a target function
by declaring it as having C linkage; for more information, see Name mangling (C++ only).
If you apply different labels to multiple declarations
of the same variable or function, the first specification is honored,
and all subsequent assembly labels are ignored with a warning.
You cannot apply an assembly label to any of the
following: