The program below works, but the array in the unit defaults to a zero-based array.
unit bar;
interface
procedure show( a: array of integer );
implementation
procedure show( a: array of integer ); var i : integer; begin for i := 1 to 4 do write( a[ i ]:7 ); writeln; end;
end.
program foo; uses bar; var a: array[1..5] of integer; i: integer; begin for i := 1 to 5 do a[i] := i; for i := 1 to 5 do write( a[i]:7 ); writeln; show( a ); end.
Russ
Russell Whitaker wrote:
The program below works, but the array in the unit defaults to a zero-based array.
Yes, that's how "open arrays" are expected to behave. Send your thanks to Borland. ;-)
Frank
On 17 Dec 2002 at 13:03, Russell Whitaker wrote:
The program below works, but the array in the unit defaults to a zero-based array.
unit bar;
interface
procedure show( a: array of integer );
IIRC, open arrays are a Borland extension, and the GPC behaviour is therefore correct. This is what the Delphi 4 help file says about open arrays:
"Within the body of a routine, open array parameters are governed by the following rules.
They are always zero-based. The first element is 0, the second element is 1, and so forth. The standard Low and High functions return 0 and Length 1, respectively. The SizeOf function returns the size of the actual array passed to the routine. They can be accessed by element only. Assignments to an entire open array parameter are not allowed. They can be passed to other procedures and functions only as open array parameters or untyped var parameters.
Instead of an array, you can pass a variable of the open array parameters base type. It will be treated as an array of length 1.
When you pass an array as an open array value parameter, the compiler creates a local copy of the array within the routines stack frame. Be careful not to overflow the stack by passing large arrays. "
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Web: http://www.bigfoot.com/~african_chief/
On Tue, Dec 17, 2002 at 01:03:13PM -0800, Russell Whitaker wrote:
The program below works, but the array in the unit defaults to a zero-based array.
Borland's "open arrays" are always zero based. Standard conformant arrays don't have this restriction:
procedure show (a: array [m .. n: integer] of integer); var i : integer; begin for i := m to n do write( a[ i ]:7 ); writeln; end;
Emil
unit bar;
interface
procedure show( a: array of integer );
implementation
procedure show( a: array of integer ); var i : integer; begin for i := 1 to 4 do write( a[ i ]:7 ); writeln; end;
end.
program foo; uses bar; var a: array[1..5] of integer; i: integer; begin for i := 1 to 5 do a[i] := i; for i := 1 to 5 do write( a[i]:7 ); writeln; show( a ); end.
Russ