6
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).
The Pascal main program,
NonPasMain.p
The commands to compile and
execute NonPas.c and
NonPasMain.p
128
See this example:
#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');
}
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
Pascal 4.0 User's Guide
Need help?
Do you have a question about the SunSoft Pascal 4.0 and is the answer not in the manual?
Questions and answers