HP SunSoft Pascal 4.0 User Manual

Page 122

Advertising
background image

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

Advertising