6

The C function, IntCA.c

The -calignoption 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:

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 }

The C–Pascal Interface

123

Page 147
Image 147
HP SunSoft Pascal 4.0 manual C function, IntCA.c, C-Pascal Interface 123