WEAK
!DIR$ WEAK
procedure_name [,procedure_name] …
!DIR$ WEAK
procedure_name=stub_name [,procedure_name1=stub_name1] …
Scope: Global
The WEAK
directive specifies an external identifier that may remain unresolved throughout the compilation. The WEAK
directive supports the following arguments:
procedure_name
A weak object in the form of a variable or procedure.
stub_name
A stub procedure that exists in the code. The stub_name will be called if a strong reference does not exist for procedure_name. The stub_name procedure must have the same name and dummy argument list as procedure_name.
A weak external does not increase the total memory requirements of a program. The WEAK
directive can prevent the compiler driver from adding the binary to a program, resulting in a smaller program and less use of memory.
The first form of the directive allows the declaration of one or more weak references on one line.
The second form allows the assigning of a strong reference to a weak reference.
Declaring an object as a weak external directs the linker to do one of these tasks:
Link the object if it is already linked. That is, if a strong reference already exists or is defined by the program, that reference will be used.
If a strong reference is specified in the weak directive (second form), and a reference is not defined by the program, then the strong reference is assigned to the weak reference.
If no strong reference exists, the object is left as an unsatisfied external. The linker does not display an unsatisfied external message for unresolved weak references.
Note that the linker treats weak externals as unsatisfied externals, so they remain silently unresolved if no strong reference occurs during compilation. Thus, it is the developer’s responsibility to ensure that run time references to weak external names do not occur unless the linker (using some “strong” reference elsewhere) has actually linked the entry point in question.
The attributes that weak externals must have depend on the form of the weak directive used:
First form, weak externals must be declared, but not defined or initialized, in the source file.
Second form, weak externals may be declared, but not defined or initialized, in the source file.
Either form, weak externals cannot be declared with a
static
storage class.