User manual

mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
193
Visibility
The visibility of an identier is that region of the program source code from which legal access to the identier’s
associated object can be made.
Scope and visibility usually coincide, though there are circumstances under which an object becomes temporarily
hidden by the appearance of a duplicate identier, i.e. the object still exists but the original identier cannot be used to
access it until the scope of the duplicate identier is ended.
Technically, visibility cannot exceed scope, but scope can exceed visibility.
Name Spaces
Name space is a scope within which an identier must be unique. The mikroBasic PRO for dsPIC30/33 and PIC24 uses
two distinct categories of identiers:
1. Global variables are visible throughout the whole unit, from the place of declaration. Also. they can be
seen in other units, if they are declared above the Implementation section.
2. Local variables, parameters, types, function results - must be unique within the block in which they are
declared.
For example:
dim level as byte
sub procedure control(dim sens as byte)
dim location as byte
location = 1
sens = location
level = 123
end sub
sub procedure temperature
location = 0 ‘ ILLEGAL
sens = 23 ‘ ILLEGAL: redenition of sens
level = 95
end sub
Place of declaration Scope
Identier is declared in the declaration section of
the main module, out of any function or procedure
Scope extends from the point where it is declared to the end of the current
le, including all routines enclosed within that scope. These identiers have
a le scope and are referred to as globals.
Identier is declared in the function or procedure Scope extends from the point where it is declared to the end of the current
routine. These identiers are referred to as locals.
Identier is declared in the interface section of the
module
Scope extends the interface section of a module from the point where it
is declared to the end of the module, and to any other module or program
that uses that module. The only exception are symbols which have a scope
limited to the le in which they are declared.
Identier is declared in the implementation section of
the module, but not within any function or procedure
Scope extends from the point where it is declared to the end of the module.
The identier is available to any function or procedure in the module.