[fpc-pascal]No runtime range checking?

Michael Van Canneyt michael.vancanneyt at wisa.be
Thu Oct 2 13:20:41 CEST 2003


On Thu, 2 Oct 2003, Andy Sy wrote:

> program blah;
>
> type
>    stringy = array[4..10] of char;
>
> var
>    C: stringy;
>    D: array[2..5] of char;
>
> procedure showstring(I:Integer);
> begin
>    Write(C[I]);
> end;
>
> begin
>    C:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
>    D:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
>    Writeln(D);
>    showstring(-5);
> end.
>


>
> FPC doesn't even complain about range exceeded whether
> during compilation or runtime...

It does:

malpertuus: ~ >ppc386 -Cr -gl testr.pp
malpertuus: ~ >./testr
ABCD
Runtime error 201 at 0x0040DC03
  0x0040DC03  SHOWSTRING,  line 12 of testr.pp
  0x0040DCA9  main,  line 19 of testr.pp
  0x0040D365

>isn't this an egregious
> violation of Pascal's strict typing philosophy?  Does
> Turbo Pascal/Delphi behave this way as well?

Delphi doesn't compile your program:
malpertuus: ~ >dcc32 /CC -$$R+ -$$P+ -$$V+ testr.pp
Borland Delphi  Version 13.0  Copyright (c) 1983,99 Inprise Corporation
E:\root\testr.pp(16) Error: Incompatible types: 'stringy' and 'String'
E:\root\testr.pp(17) Error: Incompatible types: 'Array' and 'String'
E:\root\testr.pp(20)

Michael.




More information about the fpc-pascal mailing list