Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2001-11

array dimensions bug?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aleksey V. Vaneev

Hello,

Here's some strange behaviour... it outputs

0 0
0 0
0 50

In fact this is GOOD if base index of parametrised arrays is always 0, but in my previous "array of question" you've said I must use low() and high(). So, what to assume?

procedure aaa(var a: array of Integer);
begin
writeln(low(a):10,high(a):10);
end;
var
        aa: array [0..50] of Integer;
begin
aaa(aa[0]);
aaa(aa[40]);
writeln(low(aa):10,high(aa):10);
end.

Best regards,
Aleksey

Reply by email

Jonas Maebe
to Aleksey V. Vaneev
Aleksey V. Vaneev wrote 9 lines
Here's some strange behaviour... it outputs 0 0 0 0 0 50 In fact this is GOOD if base index of parametrised arrays is always 0, but in my previous "array of question" you've said I must use low() and high(). So, what to assume?

Always use low and high. They are evaluated at compile time if possible, so you will not lose any speed and you will always get the correct results.

Show quoted text 10 lines
procedure aaa(var a: array of Integer); begin writeln(low(a):10,high(a):10); end; var aa: array [0..50] of Integer; begin aaa(aa[0]);

Shouldn't this be rejected? Passing an integer as an "array of integer"??

Jonas

Reply by email

Peter Vreman
Show quoted text 13 lines
> Here's some strange behaviour... it outputs > > 0 0 > 0 0 > 0 50 > > In fact this is GOOD if base index of parametrised arrays is always > 0, but in my previous "array of question" you've said I must use > low() and high(). So, what to assume? Always use low and high. They are evaluated at compile time if possible, so you will not lose any speed and you will always get the correct results.

open arrays start always with 0. But using low() and high() is the recommended way

Show quoted text 12 lines
> procedure aaa(var a: array of Integer); > begin > writeln(low(a):10,high(a):10); > end; > > var > aa: array [0..50] of Integer; > > begin > aaa(aa[0]); Shouldn't this be rejected? Passing an integer as an "array of integer"??

No, this is also support by delphi/tp7. It is passed as 'array[0..0] of integer'

Reply by email

Jonas Maebe
to Peter Vreman
Peter Vreman wrote 7 lines
> Always use low and high. They are evaluated at compile time if > possible, > so you will not lose any speed and you will always get the correct > results. open arrays start always with 0. But using low() and high() is the recommended way

I know, but you shouldn't say this, because people will start using 0 (even though low(a) will be replaced by "0" at compile time and as such is just as fast as using "0") and then start reporting bugs if for some reason this changes somewhere in the future for a certain kind of array :)

Show quoted text 5 lines
> Shouldn't this be rejected? Passing an integer as an "array of > integer"?? No, this is also support by delphi/tp7. It is passed as 'array[0..0] of integer'

In that case, there is no problem :)

Jonas

Reply by email