The C++–Pascal Interface
161
7
Global Variables in C++ and Pascal
If the types are compatible, a global variable can be shared between C++ and
Pascal. See this example:
The Pascal procedure,
GloVar.p
var
Year: integer;
procedure GloVar;
begin
Year := 1995;
end;
The C++ main program,
GloVarMain.cc
#include <stdio.h>
extern "C" void GloVar ();
int Year;
int main(void)
{
Year = 2042;
GloVar ();
printf (" %d \n", Year);
}
The commands to compile and
execute
GloVar.p
and
GloVarMain.cc
hostname% pc -c GloVar.p
hostname% CC GloVar.o GloVarMain.cc -lpc
hostname% a.out
1995
Summary of Contents for SunSoft Pascal 4.0
Page 14: ...xiv Pascal 4 0 User s Guide ...
Page 16: ...xvi Pascal 4 0 User s Guide ...
Page 30: ...6 Pascal 4 0 User s Guide 1 ...
Page 160: ...136 Pascal 4 0 User s Guide 6 ...
Page 268: ...244 Pascal 4 0 User s Guide 11 ...
Page 320: ...296 Pascal 4 0 User s Guide B ...
Page 331: ...Index 307 ...
Page 333: ......