HP SunSoft Pascal 4.0 Instrukcja Użytkownika Strona 122

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 333
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 121
98 Pascal 4.0 Users 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
Przeglądanie stron 121
1 2 ... 117 118 119 120 121 122 123 124 125 126 127 ... 332 333

Komentarze do niniejszej Instrukcji

Brak uwag