![](/images/backgrounds/286549/hp-sunsoft-pascal-4-0-users-manual-549395155x1.png)
6
The C function, RetReal.c
The Pascal main program, RetRealMain.p
The commands to compile and execute RetReal.c and RetRealMain.p
double RetReal(double *x)
{
return(*x + 1.0);
}
program RetRealMain; var
r, s: real;
function RetReal(var x: real): real; external c;
begin
r := 2.0;
s := RetReal(r); writeln(r: 4: 1, s: 4: 1)
end. { RetRealMain }
hostname% cc
hostname% pc RetReal.o RetRealMain.p hostname% a.out
2.0 3.0
Pascal has a special type that is a pointer to a procedure. A variable of this type can be used as a parameter, as follows:
The C function, ProcPar.c | #include <string.h> |
|
| void proc_c (void (*p)()) | /* a pointer to procedure argument */ |
| { |
|
| char *s ; |
|
| s = "Called from C"; |
|
| (*p)( s, strlen(s)); | /* Call the Pascal routine */ |
| } |
|
|
|
|
The | 131 |