setModName is used to form or remove an association between a dummy name (dummyName) for a MODULE and the actual name (actualName) of a MODULE. It is an error if dummyName and actualName are not valid MODULE names, i.e., valid MAINSAIL identifiers, unless actualName is the null STRING.
|Use of setModName may result in programs whose structure is
difficult for a human reader to understand. Wherever feasible,
XIDAK recommends using an explicit POINTER to a MODULE's
interface CLASS instead of using setModName (by doing so, it is
always possible to write a program without using setModName).|
In addition, XIDAK is planning for a future version of MAINSAIL a form of MODULE interface checking that would treat a MODULE accessed through an alias as an error. Such checking would not be the default (since making it the default would render programs using setModName invalid), but would be incompatible with the use of setModName.
Whenever a data section is to be allocated for a MODULE m (for which no data section yet exists), the current list of associations is searched to determine if m is a dummy name. If so, the corresponding actual name is used as the name of the MODULE for which the control section is found. It is not checked whether the actual name is itself a dummy name; i.e., the actual name must in fact be the name of a MODULE. Thus, a MODULE can use a dummy MODULE name to make references to a MODULE whose actual name is not known at compiletime, provided that a setModName call will associate the dummy name with the actual name at runtime.
It is not specified whether MODULE name associations (as established by setModName) have any effect on any data section for a given MODULE if another data section for the same MODULE already exists. For example, if a MODULE FOO has obtained linkage to a MODULE actually named BAR by using a dummy name BAZ for BAR, and the actual name associated with BAZ is changed by a call to setModName to GAZ, it is unspecified whether subsequently created data sections of FOO that use the dummy name BAZ obtain linkage to BAR or to GAZ.
If setModName is issued for a dummy name that is already associated with an actual name, then the new association replaces the old one.
If dummyName is the actual name of a MODULE for which a control section already exists, the effect of setModName is undefined.
The association set up by setModName(dummyName,actualName) can be released by relModName(dummyName) or setModName(dummyName,"").
Example 47–24. Use of setModName
in MODULE a
The actual MODULE referenced by the call to addGen, in MODULE b, is determined by what the user types in response to the inquiry in MODULE a. This allows MODULE b to access an anonymous MODULE, of which only the interface characteristics are known. Anonymous MODULEs of which the interfaces are known may also be accessed by explicit POINTERs, but explicit POINTERs are syntactically clumsier; however, explicit POINTERs may be required if it is necessary to execute simultaneously two different programs needing separate copies of the same MODULE.