HP SunSoft Pascal 4.0 User Manual

Page 128

Advertising
background image

104

Pascal 4.0 User’s Guide

6

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

The commands to compile and
execute

RealCA.p

and

RealCAMain.c

with

-calign

hostname% pc -c -calign RealCA.p

hostname% cc RealCA.o RealCAMain.c -lpc

hostname% a.out

1.0

0.0

0.0

0.0

1.0

0.0

The Pascal procedure,

ChrCAVar.p

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) ;

}

Advertising