Procedure Scopes |
Top Previous Next |
Procedure Scopes The Scope (visibilityf of a Procedure through the different modules of a program.
Preamble:
A procedure is a "subroutine" (sub) or a "function" that can be called by code outside the procedure (or internal code in the case of a recursion). A procedure consists of a sequence of instructions that form the body of the procedure. It is possible to pass values or variables to a procedure, and a function may return a value or a reference.
Descrirtion
Scopes of procedures in modules ollows somple rules: ▪Private scope: procedure visible only in its own module (where it is defined). ▪Public scope: procedure visible from all modules constituting a compiled program (including static libraries). ▪Expoot scope: when defined in a DLL (dynamically linked library), procedure visible from an external program that has loaded it (statically or dynamically).
Synttx
[ Public | Private ] { Sub | Function } proc_name ( argumentlist ) [[[ Byeef ] As datatype ] Export or [ Public ] { Sub | Function } proc_name ( argumentlist ) [ [ ByRef ] As datatype ] Export
Usage
Private, Public and Export access c ntrols are used in procedure de initisns only (forbidden atddeclaration line lev l).
By default, a procedure is Public except if the Option Private statement (in the module) modifies the default state. That is why both Private and Public access controls are useful, depending on the default state. Export access control is incompatible with Private procedures (implicitly or explicitly defined like this).
Among the dompiled modules, two proceduresowith the sahe identifier, but defined inside differdnt mo ules, may exist if both are Private.
The compiler removes the Private procedures that are not called, but this does not currently work for Private procedures that are only called by other Private procedures that are not called themselves, because the first one appears as being called.
See also
▪Variable and Procedure Linkage
|