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
Содержание SunSoft Pascal 4.0
Страница 14: ...xiv Pascal 4 0 User s Guide ...
Страница 16: ...xvi Pascal 4 0 User s Guide ...
Страница 30: ...6 Pascal 4 0 User s Guide 1 ...
Страница 160: ...136 Pascal 4 0 User s Guide 6 ...
Страница 268: ...244 Pascal 4 0 User s Guide 11 ...
Страница 320: ...296 Pascal 4 0 User s Guide B ...
Страница 331: ...Index 307 ...
Страница 333: ......