6

The commands to compile and execute RealCA.p and RealCAMain.c with -calign

The Pascal procedure,

ChrCAVar.p

hostname% pc -c -calign RealCA.p hostname% cc RealCA.o RealCAMain.c -lpc hostname% a.out

1.00.0 0.0

0.01.0 0.0

If wc is the width of the smallest element, as determined by sizeof(), then the width of the next largest element is the number of those smaller elements in the next larger element multiplied by wc.

width of next largest element = (ub - lb + 1) * wc

In general, (lb, ub, wc) are the bounds and element width of the next lower dimension of the array. This definition is recursive.

Example 3: Array of Characters

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

begin

a[0] := 'T';

a[13] := 'o'; end; { ChrCAVar }

The C main program, ChrCAVarMain.c. For C, the lower bound is always 0.

#include <stdio.h>

extern void ChrCAVar(char [], int, int);

int main(void)

{

static char s[] = "this is a string" ;

ChrCAVar( s, 0, sizeof(s)-1) ; /*(s, lower, upper)*/ printf("%11s \n", s) ;

}

104

Pascal 4.0 User’s Guide