8.4.2 Using EXTERN with Library Routines

In some cases, EXTERN helps you limit the size of your executable file by specifying in the syntax an alternative name for a procedure. You would use this form of the EXTERN directive when declaring a procedure or symbol that may not need to be used.

The syntax looks like this:

EXTERN [[langtype]]name[[(altname)]]:qualifiedtype

The addition of the altname to the syntax provides the name of an alternate procedure that the linker uses to resolve the external reference if the procedure given by name is not needed. Both name and altname must have the same qualifiedtype.

When the linker encounters an external definition for a procedure that gives an altname, the linker finishes processing that module before it links the object module that contains the procedure given by name. If the program does not reference any symbols in the name file's object from any of the linked modules, the assembler uses altname to satisfy the external reference. This saves space because the library object module is not brought in.

For example, assume that the contents of STARTUP.ASM include these statements:

EXTERN init(dummy)

.

.

.

dummy PROC

.

.

. ; A procedure definition containing no

ret ; executable code

dummy ENDP

.

.

.

call init ; Defined in FLOAT.OBJ

In this example, the reference to the routine init (defined in FLOAT.OBJ) does not force the module FLOAT.OBJ to be linked into the executable file. If another reference causes FLOAT.OBJ to be linked into the executable file, then init will refer to the init label in FLOAT.OBJ. If there are no references which force FLOAT.OBJ to be loaded, then the alternate name for init(dummy) will be used by the linker.