Sign in Join

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

Mailing lists / fpc-pascal / 2005-05

Arrays in debugger; No range errors on arrays

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Lance Boyle

Hi list,

I'm playing with FPC 2.0.0 on OS X 10.3.9 using Xcode 1.5. I run the following little program...

program dumpmePascal;
    uses
      EmptyPlaceHolderUnit;
    var
       i : integer;
       topArray : array[10..13] of real;
       {debugger doesn't show this array at all--discussed previously
       on this list}
begin
    for i := 10 to 13 do     {OK}
       topArray[i] := sqr(i);
    for i := 10 to 13 do     {OK}
       writeln(topArray[i]);
    for i := 20 to 23 do     {OK too! No range error reported.}
       topArray[i] := sqr(i);
    for i := 20 to 23 do     {prints correct squares}
       writeln(topArray[i]);
    printstuff;
end.
unit EmptyPlaceHolderUnit;
interface
     procedure printstuff;
implementation
     procedure printstuff;
         var
         j : longint;
         anArray      : array[1..4] of real;
         {debuger shows anArray as 0..3, with incorrect value for
"anArray[0]"}
         anotherArray : array[21..24] of real;
         {debuger shows anotherArray as 0..3, with incorrect value for
all}
     begin
         for j := 1 to 4 do
             anArray[j] := 3 * j;
         for j := 1 to 4 do
             writeln(anArray[j]);
         anArray[205] := 12345.6789;     {No range error reported}
         writeln(anArray[205]);          {No range error reported}
         {Trying to write to anArray[206 and higher causes}
         {runtime error 216.}
         for j := 21 to 24 do            {OK}
             anotherArray[j] := 2 * j;
         for j := 21 to 24 do            {OK}
             writeln(anotherArray[j]);
         for j := 31 to 34 do
             anotherArray[j] := 2 * j;   {No range error reported}
         for j := 41 to 44 do
             writeln(anotherArray[j]);   {No range error reported}
     end;
end.

...and get the following output:

[Session started at 2005-05-24 04:55:42 -0700.]
1.00000000000000E+002
1.21000000000000E+002
1.44000000000000E+002
1.69000000000000E+002
4.00000000000000E+002
4.41000000000000E+002
4.84000000000000E+002
5.29000000000000E+002
3.00000000000000E+000
6.00000000000000E+000
9.00000000000000E+000
1.20000000000000E+001
1.23456789000000E+004
4.20000000000000E+001
4.40000000000000E+001
4.60000000000000E+001
4.80000000000000E+001
0.00000000000000E+000
4.94065645841247E-324
-4.28882459806687E-232
-3.51094486606932E-232

Executable “dumpmePascal” has exited with status 0.

As I've indicated in some of the comments, there appears to be some range checking issues--is range checking off by default?

A second issue is that arrays that begin with any index other than 0 seem to be displayed incorrectly in the debugger window of Xcode.

Jerry

Reply by email

Jonas Maebe
to Lance Boyle
Lance Boyle wrote
As I've indicated in some of the comments, there appears to be some range checking issues--is range checking off by default?

Yes, it is. Add {$r+} at the top of your source to turn it on, or add "-Cr" to the command line options of the compiler.

A second issue is that arrays that begin with any index other than 0 seem to be displayed incorrectly in the debugger window of Xcode.

That's a problem of gdb not properly supporting Pascal arrays, which indeed can start at an index 0. There is a set of patches to create gdbpas, which may have this fixed, but I haven't built it for Mac OS X yet (also, you'd probably have to overwrite the system's gdb with this gdbpas for XCode to use it).

Jonas

Reply by email

L505
to Lance Boyle: I'm playing with FPC 2.0.0 on OS X 10.3.9 using Xcode 1.5. I run the following little…
From the mailing list:

http://www.nl.freepascal.org/lists/fpc-pascal/2003-October/006123.html

I read a bit about range checking there.

Earlier message 10 lines
----- Original Message ----- From: "Lance Boyle" As I've indicated in some of the comments, there appears to be some range checking issues--is range checking off by default? A second issue is that arrays that begin with any index other than 0 seem to be displayed incorrectly in the debugger window of Xcode. Jerry

Reply by email

Lance Boyle
to Jonas Maebe: Yes, it is. Add {$r+} at the top of your source to turn it on, or add "-Cr" to the…
Jonas Maebe wrote 8 lines
On 24 mei 2005, at 13:58, Lance Boyle wrote: > As I've indicated in some of the comments, there appears to be some > range checking issues--is range checking off by default? Yes, it is. Add {$r+} at the top of your source to turn it on, or add "-Cr" to the command line options of the compiler.

Thanks, Jonas.

Well--that's just lovely. How about getting this fixed? What other surprises should I know about before using FPC?

Side comment--It's partly the Pascal-dialect problem that is driving me to do most of my new programming in Ada (Ada = no dialects). For the interested:
(Mac users: go to www.macada.org for GNAT, a free, gcc-based, absolutely stunning Ada compiler that works with Xcode.) (All: go to http://www.cs.nyu.edu/cs/faculty/schonber/gnat.html) (To convert Pascal to Ada: Google p2ada)
(For a complete THINK Pascal library emulation in Ada, go to http://www.chez.com/blady/creations.html#ada_thp).

Show quoted text 9 lines
> A second issue is that arrays that begin with any index other than 0 > seem to be displayed incorrectly in the debugger window of Xcode. That's a problem of gdb not properly supporting Pascal arrays, which indeed can start at an index 0. There is a set of patches to create gdbpas, which may have this fixed, but I haven't built it for Mac OS X yet (also, you'd probably have to overwrite the system's gdb with this gdbpas for XCode to use it).

I wonder if I would be able to specify gdbpas only when using FPC and the regular gdb otherwise? (And the Ada-patched gdb for Ada 8^) ?

Jonas

Reply by email

Lance Boyle
to L505: http://www.nl.freepascal.org/lists/fpc-pascal/2003-October/006123.html I read a bit about…
L505 wrote
> From the mailing list: http://www.nl.freepascal.org/lists/fpc-pascal/2003-October/006123.html I read a bit about range checking there.

Thanks--a good reference to what is apparently a long-standing problem.

Show quoted text 11 lines
----- Original Message ----- From: "Lance Boyle" As I've indicated in some of the comments, there appears to be some range checking issues--is range checking off by default? A second issue is that arrays that begin with any index other than 0 seem to be displayed incorrectly in the debugger window of Xcode. Jerry

Reply by email

Marco van de Voort
to Lance Boyle: Thanks, Jonas. Well--that's just lovely. How about getting this fixed? What other…
Show quoted text 9 lines
On May 24, 2005, at 5:31 AM, Jonas Maebe wrote: >> range checking issues--is range checking off by default? > > Yes, it is. Add {$r+} at the top of your source to turn it on, or add > "-Cr" to the command line options of the compiler. Thanks, Jonas. Well--that's just lovely. How about getting this fixed?

It's by design, since normal for Borland + compatibles.

What other surprises should I know about before using FPC?

That depends on your mindset. I don't know enough about Ada, but since GNAT is a gcc derivate, expect better compile speed with FPC :-)

(All: go to http://www.cs.nyu.edu/cs/faculty/schonber/gnat.html) (To convert Pascal to Ada: Google p2ada) (For a complete THINK Pascal library emulation in Ada, go to http://www.chez.com/blady/creations.html#ada_thp).

More interesting would be the other way around.

Show quoted text 8 lines
> That's a problem of gdb not properly supporting Pascal arrays, which > indeed can start at an index 0. There is a set of patches to create > gdbpas, which may have this fixed, but I haven't built it for Mac OS X > yet (also, you'd probably have to overwrite the system's gdb with this > gdbpas for XCode to use it). I wonder if I would be able to specify gdbpas only when using FPC and the regular gdb otherwise? (And the Ada-patched gdb for Ada 8^) ?

Well, maybe all non mainstream GDB users should gang up and try to get more GDB support accepted. (I assume Ada can make arrays start at non zero too?)

However this is a significant amount of work. Pierre did this for a while, which really bumped GDB usability with FPC.

Reply by email

Lance Boyle
to Marco van de Voort
Marco van de Voort wrote 11 lines
> On May 24, 2005, at 5:31 AM, Jonas Maebe wrote: >>> range checking issues--is range checking off by default? >> >> Yes, it is. Add {$r+} at the top of your source to turn it on, or add >> "-Cr" to the command line options of the compiler. > > Thanks, Jonas. > > Well--that's just lovely. How about getting this fixed? It's by design, since normal for Borland + compatibles.

Well, OK--at least there is a reason.

Show quoted text 6 lines
> What other surprises should I know about before using FPC? That depends on your mindset. I don't know enough about Ada, but since GNAT is a gcc derivate, expect better compile speed with FPC :-)

True. But I still haven't played with the background compiling and smart linking in Xcode.

Show quoted text 24 lines
> (All: go to http://www.cs.nyu.edu/cs/faculty/schonber/gnat.html) > (To convert Pascal to Ada: Google p2ada) > (For a complete THINK Pascal library emulation in Ada, go to > http://www.chez.com/blady/creations.html#ada_thp). More interesting would be the other way around. >> That's a problem of gdb not properly supporting Pascal arrays, which >> indeed can start at an index 0. There is a set of patches to >> create >> gdbpas, which may have this fixed, but I haven't built it for Mac OS >> X >> yet (also, you'd probably have to overwrite the system's gdb with >> this >> gdbpas for XCode to use it). > > I wonder if I would be able to specify gdbpas only when using FPC and > the regular gdb otherwise? (And the Ada-patched gdb for Ada 8^) ? Well, maybe all non mainstream GDB users should gang up and try to get more GDB support accepted. (I assume Ada can make arrays start at non zero too?)

That's correct.

Show quoted text 5 lines
However this is a significant amount of work. Pierre did this for a while, which really bumped GDB usability with FPC.

Reply by email

Florian Klaempfl
to Lance Boyle: Thanks, Jonas. Well--that's just lovely. How about getting this fixed? What other…
Lance Boyle wrote
Well--that's just lovely. How about getting this fixed? What other surprises should I know about before using FPC?

I wonder how you can be suprised, it's perfectly documented: http://www.freepascal.org/docs-html/prog/progsu46.html#x53-510001.1.46

If you didn't use a Borland compatible compiler before, reading the manual isn't a bad idea.

Show quoted text 10 lines
Side comment--It's partly the Pascal-dialect problem that is driving me to do most of my new programming in Ada (Ada = no dialects). For the interested: (Mac users: go to www.macada.org for GNAT, a free, gcc-based, absolutely stunning Ada compiler that works with Xcode.) (All: go to http://www.cs.nyu.edu/cs/faculty/schonber/gnat.html) (To convert Pascal to Ada: Google p2ada) (For a complete THINK Pascal library emulation in Ada, go to http://www.chez.com/blady/creations.html#ada_thp).

I guess this is a pascal list here and no ada advertisement list?

Reply by email

L505
to Florian Klaempfl

| I guess this is a pascal list here and no ada advertisement list? |

no, n'ada ada ada-vertisement list
(sorry, could n'ada resisted.)

I was looking into ada the other day on some wikis, though. Have to check deeper into its origins.

Reply by email