weak

Date:

06-19-2023

NAME

weak - Specifies an external identifier that may remain unresolved

SYNOPSIS

!DIR$ WEAK procedure_name [, procedure_name] ...
!DIR$ WEAK procedure_name = stub_name[, procedure_name1 = stub_name1] ...
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.

DESCRIPTION

Scope: Global

The weak directive specifies an external identifier that may remain unresolved throughout the compilation. A weak external reference can be a reference to a function or to a data object. A weak external does not increase the total memory requirements of your program. The weak directive can prevent the compiler driver from adding the binary to your program, resulting in a smaller program and less use of memory.

The weak directive must appear at global scope.

The first form of the directive allows you to declare one or more weak references on one line. In Fortran, this form requires you to implement code that senses that the procedure_name procedure is linked before calling it.

The second form allows you to assign a strong reference to a weak reference.

Declaring an object as a weak external directs the linker to do one of these tasks:

  • Links 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. (that is, if a strong reference exists.)

  • 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: The linker treats weak externals as unsatisfied externals, so they remain silently unresolved if no strong reference occurs during compilation. Thus, it is your 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 that you use (see Example 1):

  • 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.

SEE ALSO

intro_directives(7)