Download Documentation for Pic Micro Pascal

Transcript
PIC MICRO PASCAL V1.6 - USER MANUAL
3.14.4 Open array parameters
An open array parameter is a way to pass an array for which the dimension is not known, or to pass arrays
with different sizes.
Example:
PROCEDURE Test(X: ARRAY OF integer);
BEGIN
FOR I := LOW(X) TO HIGH(X) DO
X[I] := I * I;
END;
VAR
X0: ARRAY[1..5] OF integer;
X1: ARRAY[-2..20] OF integer;
…
Test(X0);
Test(X1);
When an array is passed as an open array parameter, its bounds are shifted so that low bound is zero, so
the low() pseudo function applied to an open array always returns 0.
An Open array parameter is always passed by address. The open array pseudo variable (X in the example)
is allocated as a pointer but occupies also an additional RAM space that is used to pass the actual high
bound of the array.
Open arrays may be passed as an argument to another procedure or function.
Open arrays cannot be assigned globally, only elements may be accessed.
3.14.5 Forward procedures and functions
Procedures and functions may be declared as forward (standard Pascal); the forwarded declaration
argument list or function result must match the first declaration, or may be omitted.
Example:
PROCEDURE ForwardProc2(VAR X: INTEGER; Y: BYTE); FORWARD;
PROCEDURE Proc1;
VAR
A: INTEGER;
BEGIN
ForwardProc2(A, 12); // sets A to 12
END;
PROCEDURE ForwardProc2;
BEGIN
X := Y;
END;
Document revision: A
LANGUAGE
F E AT U R E S
- PROCEDURE
AND
FUNCTION
D E C L AR AT I O N
Page 55/101