Datasheet

SCOPE AND VISIBILITY
Scope
The scope of an identifier is a part of the program in which the identifier can be used
to access its object. There are different categories of scope: block (or local), func-
tion, function prototype, and file. These categories depend on how and where iden-
tifiers are declared.
- Block: The scope of an identifier with block (or local) scope starts at the
declaration point and ends at the end of the block containing the declara-
tion (such block is known as the enclosing block). Parameter declarations
with a function definition also have block scope, limited to the scope of the
function body.
- File: File scope identifiers, also known as globals, are declared outside of
all blocks; their scope is from the point of declaration to the end of the
source file.
- Function: The only identifiers having function scope are statement labels.
Label names can be used with goto statements anywhere in the function
in which the label is declared. Labels are declared implicitly by writing
label_name: followed by a statement. Label names must be unique within
a function.
- Function prototype: Identifiers declared within the list of parameter dec-
larations in a function prototype (not as a part of a function definition) have a
function prototype scope. This scope ends at the end of the function prototype.
Visibility
The visibility of an identifier is a region of the program source code from which an
identifier’s associated object can be legally accessed.
Scope and visibility usually coincide, though there are circumstances under which
an object becomes temporarily hidden by the appearance of a duplicate identifier:
the object still exists but the original identifier cannot be used to access it until the
scope of the duplicate identifier ends.
Technically, visibility cannot exceed a scope, but a scope can exceed visibility. See
the following example:
144
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5