The C–Pascal Interface
121
6
Fixed Arrays
For a fixed-array parameter, pass the same type and size, as in this example:
The
-calign
option is not needed for this example, but may be necessary if
the array parameter is an array of aggregates.
The C function,
FixVec.c
void FixVec(int V[9], int *Sum)
{
int i;
*Sum = 0;
for (i = 0; i <= 8; i++)
*Sum = *Sum + V[i];
}
The Pascal main program,
FixVecMain.p
program FixVecMain(output);
type
TVec = array [0..8] of integer;
var
V: TVec := [0, 1, 2, 3, 4, 5, 6, 7, 8];
Sum: integer;
procedure FixVec(var XV: TVec; var XSum: integer); external c;
begin
FixVec(V, Sum);
writeln(Sum: 3);
end. { FixVecMain }
The commands to compile and
execute
FixVec.c
and
FixVecMain.p
hostname% cc -c FixVec.c
hostname% pc -calign FixVec.o FixVecMain.p
hostname% a.out
36
Содержание 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: ......