98
Pascal 4.0 User’s Guide
6
Although it does not apply in this example, arrays of aggregates in Pascal
have, by default, a size that is always a multiple of four bytes. When you use
the
-calign
option to compile the Pascal code, that difference with C is
eliminated.
The following example illustrates this point. The string
'Sunday'
only gets
through to the C main program when you compile the Pascal routine using
-calign
.
The Pascal procedure,
FixVec.p
type
VecTyp = array [0..8] of integer;
procedure FixVec(var V: TVec; var Sum: integer);
var
i: integer;
begin
Sum := 0;
for i := 0 to 8 do
Sum := Sum + V[i]
end; { FixVec }
The C main program,
FixVecMain.c
#include <stdio.h>
extern void FixVec(int [], int *);
int main(void)
{
int Sum;
static int a[] = {0,1,2,3,4,5,6,7,8};
FixVec(a, &Sum);
printf(" %d \n", Sum);
}
The commands to compile and
execute
FixVec.p
and
FixVecMain.c
hostname% pc -c -calign FixVec.p
hostname% cc FixVec.o FixVecMain.c -lpc
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: ......