Some libaries or code blocks have variables which they export. You can access these variables much in the same way as external functions. To access an external variable, you declare it as follows:
Var
MyVar : MyType; external name 'varname'; |
The e ect of this declaration is twofold:
The variable will be accessible with it's declared name, i.e. MyVar in this case.
A second possibility is the declaration:
Var
varname : MyType; cvar; external; |
The e ect of this declaration is twofold as in the previous case:
The rst possibility allows you to change the name of the external variable for internal use.
As an example, let's look at the following C le (in extvar.c):
/*
Declare a variable, allocate storage */ int extvar = 12; |
And the following program (in extdemo.pp):
Program ExtDemo;
{$L extvar.o} Var { Case sensitive declaration !! } extvar : longint; cvar;external; I : longint; external name 'extvar'; begin { Extvar can be used case insensitive !! } Writeln ('Variable ''extvar'' has value: ',ExtVar); Writeln ('Variable ''I'' has value: ',i); end. |
Compiling the C le, and the pascal program:
gcc -c -o extvar.o extvar.c
ppc386 -Sv extdemo |
Will produce a program extdemo which will print
Variable 'extvar' has value: 12
Variable 'I' has value: 12 |
on your screen.