Sharing declarations in multiple units – HP SunSoft Pascal 4.0 User Manual

Page 111

Advertising
background image

Separate Compilation

87

5

Sharing Declarations in Multiple Units

Using

extern

and

external

directives for procedure and function

declarations, you can optionally specify the source language of a separately
compiled procedure or function. For example,

extern fortran

directs the

compiler to generate calling sequences compatible with the

FORTRAN

compiler from SunSoft

. Then,

external c

directs the compiler to generate

calling sequences compatible with SunSoft C compiler.

The module unit,

ext_mod.p

module ext_mod;

define

global, proc;

%include "extern.h";

procedure proc;

begin

writeln('From PROC : ',global);

global := global + 1;

end; { proc }

The

include

file,

extern.h

var

global : extern integer;

procedure proc; extern;

The commands to compile and
execute

ext_prog.p

and

ext_mod.p

hostname% pc -xl ext_prog.p ext_mod.p

ext_prog.p:

ext_mod.p:

Linking:

hostname% a.out

From MAIN, before PROC: 1

From PROC : 1

From MAIN, after PROC: 2

Advertising