6

See this example:

The C function, NonPas.c. In the function for_C, s is a pointer (declared var in the procedure declaration), and len is not a pointer (not declared var in the procedure declaration). In the function for_nonpascal, s is still a pointer (though not declared var in the procedure declaration), and len is now a pointer (though not declared var).

#include <stdio.h>

void for_C(char *s, int len)

{

int i;

for (i = 0; i < len; i++) putchar(s[i]);

putchar('\n');

}

void for_NonPascal(char *s, int *len)

{

int i;

for (i = 0; i < *len; i++) putchar(s[i]);

putchar('\n');

}

The Pascal main program, NonPasMain.p

The commands to compile and execute NonPas.c and

NonPasMain.p

program NonPasMain; var

s: string;

procedure for_C(var s: string; len: integer); external c;

procedure for_NonPascal(var s: string; len: integer); nonpascal;

begin

s :='Hello from Pascal'; for_C(s, 18); for_NonPascal(s, 18);

end. { NonPasMain }

hostname% cc -c NonPas.c hostname% pc NonPas.o NonPasMain.p hostname% a.out

Hello from Pascal

Hello from Pascal

128

Pascal 4.0 User’s Guide

Page 152
Image 152
HP SunSoft Pascal 4.0 manual 128