128
Pascal 4.0 User’s Guide
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
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 }
The commands to compile and
execute
NonPas.c
and
NonPasMain.p
hostname% cc -c NonPas.c
hostname% pc NonPas.o NonPasMain.p
hostname% a.out
Hello from Pascal
Hello from Pascal
Содержание SunSoft Pascal 4.0
Страница 14: ...xiv Pascal 4 0 User s Guide ...
Страница 16: ...xvi Pascal 4 0 User s Guide ...
Страница 30: ...6 Pascal 4 0 User s Guide 1 ...
Страница 160: ...136 Pascal 4 0 User s Guide 6 ...
Страница 268: ...244 Pascal 4 0 User s Guide 11 ...
Страница 320: ...296 Pascal 4 0 User s Guide B ...
Страница 331: ...Index 307 ...
Страница 333: ......