HP SunSoft Pascal 4.0 User Manual

Page 126

Advertising
background image

102

Pascal 4.0 User’s Guide

6

Examples of single-dimension, multidimension, and array-of-character
conformant arrays follow. Conformant arrays are included here only because
they are a relatively standard feature; there are usually more efficient and
simpler ways to do the same thing.

Example 1: Single-Dimension Array

The Pascal procedure,

IntCA.p

. Pascal passes the

bounds pair

.

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

begin

a[1] := 1;

a[2] := 2

end; { IntCA }

The C main program,

IntCAMain.c

#include <stdio.h>

extern void IntCA(int [], int, int);

int main(void)

{

int k ;

static int s[] = { 0, 0, 0 };

IntCA (s, 0, sizeof(s)-1);

for (k=0 ; k < 3 ; k++)

printf(" %d \n", s[k]);

}

The commands to compile and
execute

IntCA.p

and

IntCAMain.c

with

-calign

hostname% pc -c -calign IntCA.p

hostname% cc IntCA.o IntCAMain.c -lpc

hostname% a.out

0

1

2

Advertising