7

The Pascal function,

RetReal.p

The C++ main program,

RetRealMain.cc

Simple Types

Simple types pass in a straightforward way, as in the following example:

function RetReal (r: real): real;

begin

RetReal := r + 1 end;

#include <stdio.h>

extern "C" double RetReal (double);

int main(void)

{

double r, s; r = 2.0;

s = RetReal (r);

printf (" %f \n", s);

}

The commands to compile and execute RetReal.p and

RetRealMain.cc

hostname% pc -c RetReal.p

hostname% CC RetReal.o RetRealMain.cc -lpchostname% a.out

3.000000

The C++–Pascal Interface

153

Page 177
Image 177
HP SunSoft Pascal 4.0 manual Commands to compile and execute RetReal.p, Hostname% pc -c RetReal.p, C++-Pascal Interface 153