It is possible to restrict the availability of objects declared in a module made visible use association by using the ONLY clause of the USE statement. In this way name clashes can be avoided by only using those objects which are necessary. It has the following form:
USE < module-name > [ ONLY:
< only-list >...]
The < only-list > can also contain renames (=>
).
This method can be used as an alternative to renaming module entities, for example, a situation may arise where a user wishes to use 1 or 2 objects from a module but discovers that if the module is accessed by use association there are a couple of hundred name clashes. The simplest solution to this is to only allow the 1 or 2 objects to be seen by his / her program. These 1 or 2 objects can be renamed if desired.
For example,
USE Stack, ONLY:Pos, IntegerPop => PopOnly Pos and Pop are made accessible and the latter is renamed.
The USE statement, with its renaming and restrictive access facilities, gives great user control enabling two modules with similar names to be accessed by the same program with only minor inconvenience. In addition, the ONLY clause gives the compiler the option of just including the object code associated with the entities specified instead of the code for the whole module. This has the potential to make the executable code smaller and faster.
Return to corresponding overview page