Stavo facendo delle prove quando ho visto uno strano comportamento di un array.
Per prova, ho scritto questo:
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
var
arr : Array [1..10] of Integer;
i, c : Integer;
begin
WriteLn(Low(arr), '..', High(arr));
c := 14;
for i := 0 to c do begin
arr[i] := i;
end;
WriteLn('Array Creato');
for i := 0 to c do begin
WriteLn(arr[i]);
end;
end.
Il cui risultato è questo:
1..10
Array Creato
0
1
2
3
4
5
6
7
8
9
10
11
12
Se uso c := 15, il risultato è:
1..10
Errore di segmentazione (core dump creato)
Non è strano? Non dovrei avere un errore sia in assegnazione che in lettura anche con il primo codice? Devo sempre usare Low() e High() anche per array statici?