Sign in Join

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

Mailing lists / fpc-devel / 2001-10

Another FPC versus Delphi issue

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Tom Verhoeff

While using FreePascal in our Programming Education and Contest Hosting system (PEACH), we encountered another issue. Consider this program (students try strange things):

program LongArray;
var
  a: array [ Integer ] of Integer;
  i: Integer;
begin
  for i := 0 to 1000 do begin
    a [ i ] := i
  end { for i }
; writeln ( a [ 1000 ] )
end.

Under Delphi (v5) this gives an compile-time error (Data type too large: exceeds 2GB). Under fpc 1.0.4 it works without options (Integer is 16 bit), and crashes with option -Sd (Delphi mode, Integer is 32 bit): Segmentation fault. Also fpc 1.1 made it crash. By the way, WITHOUT option -gl (to get more extensive runtime error info), the crash is "silent", and you can only see it when you examine the exit status, which is 103 (file not open!?) or 139 when using option -Cr (range checking).

It seems to me that fpc should give a compile-time error, rather than crash.

Tom Verhoeff

Reply by email

Peter Vreman
Show quoted text 30 lines
While using FreePascal in our Programming Education and Contest Hosting system (PEACH), we encountered another issue. Consider this program (students try strange things): program LongArray; var a: array [ Integer ] of Integer; i: Integer; begin for i := 0 to 1000 do begin a [ i ] := i end { for i } ; writeln ( a [ 1000 ] ) end. Under Delphi (v5) this gives an compile-time error (Data type too large: exceeds 2GB). Under fpc 1.0.4 it works without options (Integer is 16 bit), and crashes with option -Sd (Delphi mode, Integer is 32 bit): Segmentation fault. Also fpc 1.1 made it crash. By the way, WITHOUT option -gl (to get more extensive runtime error info), the crash is "silent", and you can only see it when you examine the exit status, which is 103 (file not open!?) or 139 when using option -Cr (range checking). It seems to me that fpc should give a compile-time error, rather than crash.

It allocates only 4 bytes for the array. That will result in memory overwritting and the strange behaviour you write.

Reply by email

KJK::Hyperion
to Peter Vreman
you wrote 9 lines
[...] > a: array [ Integer ] of Integer; [...] > Under Delphi (v5) this gives an compile-time error (Data type too > large: exceeds 2GB) [...] > It seems to me that fpc should give a compile-time error, rather > than crash. It allocates only 4 bytes for the array.

Why? Isn't Integer a range type?

Reply by email

Jonas Maebe
to KJK::Hyperion
Show quoted text 10 lines
> > a: array [ Integer ] of Integer; > [...] > > Under Delphi (v5) this gives an compile-time error (Data type too > > large: exceeds 2GB) > [...] > > It seems to me that fpc should give a compile-time error, rather > > than crash. > It allocates only 4 bytes for the array. Why? Isn't Integer a range type?

Yes, but in Delphi integer = longint and this cause the size calculation of the array in the compiler to overflow. It's fixed now (the calculation is now done with int64's instead of longints).

Jonas

Reply by email