Conformant arrays – HP SunSoft Pascal 4.0 User Manual

Page 147

Advertising
background image

The C–Pascal Interface

123

6

The

-calign

option is not needed for this example, but may be necessary if

the array parameter is an array of aggregates.

Conformant Arrays

For single-dimension conformant arrays, pass upper and lower bounds placed
after the declared parameter list. If the array is multidimensional, pass
element widths as well, one element width for each dimension, except the last
one. Chapter 8, “The FORTRAN–Pascal Interface,” has an example of
multidimensional conformant array passing.

The following example uses a single-dimension array:

The C function,

IntCA.c

void IntCA(int a[], int lb, int ub)

{

int k;

for (k=0; k <= ub - lb; k++)

a[k] = 4;

}

The Pascal main program,

IntCAMain.p

. Note that what

Pascal passes as

s

, is received

in C as

a

,

lb

,

ub

.

program IntCAMain(output);

var

s: array [1..3] of integer;

i: integer;

procedure IntCA(var a: array [lb..ub: integer] of integer);

external c;

begin

IntCA(s);

for i := 1 to 3 do

write(s[i]);

writeln

end. { IntCAMain }

Advertising