HP C/iX Reference Manual (31506-90011)
Chapter 2 13
Lexical Elements
Identifiers
Finally, identifiers cannot have the same spelling as reserved words. For example, int
cannot be used as an identifier because it is a reserved word. INT is a valid identifier
because it has different case letters.
Identifier Scope
The scope of an identifier is the region of the program in which the identifier has meaning.
There are four kinds of scope:
1. File Scope — Identifiers declared outside of any block or list of parameters have scope
from their declaration point until the end of the translation unit.
2. Function Prototype Scope — If the identifier is part of the parameter list in a
function declaration, then it is visible only inside the function declarator. This scope
ends with the function prototype.
3. Block Scope — Identifiers declared inside a block or in the list of parameter
declarations in a function definition have scope from their declaration point until the
end of the associated block.
4. Function Scope — Statement labels have scope over the entire function in which they
are defined. Labels cannot be referenced outside of the function in which they are
defined. Labels do not follow the block scope rules. In particular, goto statements can
reference labels that are defined inside iteration statements. Label names must be
unique within a function.
A preprocessor macro is visible from the #define directive that declares it until either the
end of the translation unit or an #undef directive that undefines the macro.
Identifier Linkage
An identifier is bound to a physical object by the context of its use. The same identifier can
be bound to several different objects at different places in the same program. This
apparent ambiguity is resolved through the use of scope and name spaces. The term name
spaces refers to various categories of identifiers in C (see "Name Spaces" later in this
chapter for more information).
Similarly, an identifier declared in different scopes or in the same scope more than once
can be made to refer to the same object or function by a process called linkage. There are
three kinds of linkage:
1. Internal — Within a single translation unit, each instance of an identifier with
internal linkage denotes the same object or function.
2. External — Within all the translation units and libraries that constitute an entire
program, each instance of a particular identifier with external linkage denotes the same
object or function.
3. None — Identifiers with no linkage denote unique entities.
If an identifier is declared at file scope using the storage-class specifier static, it has
internal linkage.
If an identifier is declared using the storage-class specifier extern, it has the same linkage
as any visible declaration of the identifier with file scope. If there is no visible declaration
with file scope, the identifier has external linkage.