8.3.1 PUBLIC and EXTERN

The PUBLIC and EXTERN directives are less flexible than EXTERNDEF and PROTO because they are module-specific: PUBLIC must appear in the defining module and EXTERN must appear in the calling modules. This section shows how to use PUBLIC and EXTERN. Information on where to place the external declarations in your file is in Section 8.2.3, “Positioning External Declarations.”

The PUBLIC directive makes a name visible outside the module in which it is defined. This gives other program modules access to that identifier.

The EXTERN directive performs the complementary function. It tells the assembler that a name referenced within a particular module is actually defined and declared public in another module that will be specified at link time.

A PUBLIC directive can appear anywhere in a file. Its syntax is

PUBLIC [[langtype]]name[[,[[langtype]]name]] ...

The name must be the name of an identifier defined within the current source file. Only code labels, data labels, procedures, and numeric equates can be declared public.

If you specify the langtype field here, it overrides the language specified by .MODEL. The langtype field can be C, SYSCALL, STDCALL, PASCAL, FORTRAN, or BASIC. Section 7.3.3, “Declaring Parameters with the PROC Directive,” and Section 20.1, “Naming and Calling Conventions,” provide more information on specifying langtype types.

The EXTERN directive tells the assembler that an identifier is external—defined in some other module that will be supplied at link time. Its syntax is

EXTERN [[langtype]]name:{ABS|qualifiedtype}

Section 1.2.6, “Data Types,” describes qualifiedtype. The ABS (absolute) keyword can be used only with external numeric constants. ABS causes the identifier to be imported as a relocatable unsized constant. This identifier can then be used anywhere a constant can be used. If the identifier is not found in another module at link time, the linker generates an error.

In the following example, the procedure BuildTable and the variable Var are declared public. The procedure uses the Pascal naming and data-passing conventions: