HP SunSoft Pascal 4.0 Bedienungsanleitung Seite 155

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 333
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 154
The C–Pascal Interface 131
6
Parameters That Are Pointers to Procedures
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, RetReal.c double RetReal(double *x)
{
return(*x + 1.0);
}
The Pascal main program,
RetRealMain.p
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 }
The commands to compile and
execute RetReal.c and
RetRealMain.p
hostname% cc -c RetReal.c
hostname% pc RetReal.o RetRealMain.p
hostname% a.out
2.0 3.0
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 */
}
Seitenansicht 154
1 2 ... 150 151 152 153 154 155 156 157 158 159 160 ... 332 333

Kommentare zu diesen Handbüchern

Keine Kommentare