* ada loops @ 2003-05-30 15:44 Roman V. Isaev 2003-05-30 16:00 ` Bill Findlay ` (2 more replies) 0 siblings, 3 replies; 19+ messages in thread From: Roman V. Isaev @ 2003-05-30 15:44 UTC (permalink / raw) I've got bitten by this (code was translated from pascal by p2ada, so please don't bash using goto): for Ijk in 1 .. 40 loop Sss:=Fnmis-Si(Ijk); if Sss<0.0 then goto Label_1; end if; end loop; -- IJK <<Label_1>> null; Before the loop Ijk is 0, after the loop Ijk is still 0. Huh? Why? I replaced Ijk with temp variable and put Ijk := temp before goto and it solved the problem, but why we can't have final value when we break out of the loop? What's the logic behind this language behaviour? Also when I try to debug this in GVD I can see Ijk variable, but not Sss (it's a global variable described in outer procedure). I see following message in the bottom window: (gdb) print Sss Cannot access memory at address 0x24803ec How to look up these variables? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 15:44 ada loops Roman V. Isaev @ 2003-05-30 16:00 ` Bill Findlay 2003-05-30 16:17 ` Robert A Duff 2003-05-30 17:25 ` Stephen Leake 2 siblings, 0 replies; 19+ messages in thread From: Bill Findlay @ 2003-05-30 16:00 UTC (permalink / raw) On 30/5/03 16:44, in article d3ba4d4c.0305300744.520de992@posting.google.com, "Roman V. Isaev" <rm@gunlab.com.ru> wrote: > I've got bitten by this (code was translated from pascal by p2ada, so > please don't bash using goto): > > for Ijk in 1 .. 40 loop > Sss:=Fnmis-Si(Ijk); > if Sss<0.0 then > goto Label_1; > end if; > end loop; -- IJK > <<Label_1>> null; > > Before the loop Ijk is 0, after the loop Ijk is still 0. Huh? Why? I > replaced Ijk with temp variable and put Ijk := temp before goto and > it solved the problem, but why we can't have final value when we break > out of the loop? What's the logic behind this language behaviour? P2Ada has mis-translated your Pascal program. In Pascal, the Ijk variable was used and updated by the Pascal for loop. In Ada, loop-controlled "variables" are actually local constants of the loop body. Thus your (mis-)translated code has TWO objects called Ijk: the one appearing outside the loop, and declared by you; and the one appearing inside the loop and declared by the loop command. -- Bill-Findlay chez blue-yonder.co.uk ("-" => "") ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 15:44 ada loops Roman V. Isaev 2003-05-30 16:00 ` Bill Findlay @ 2003-05-30 16:17 ` Robert A Duff 2003-05-30 16:46 ` Bill Findlay 2003-05-30 16:51 ` Bill Findlay 2003-05-30 17:25 ` Stephen Leake 2 siblings, 2 replies; 19+ messages in thread From: Robert A Duff @ 2003-05-30 16:17 UTC (permalink / raw) rm@gunlab.com.ru (Roman V. Isaev) writes: > I've got bitten by this (code was translated from pascal by p2ada, so > please don't bash using goto): > > for Ijk in 1 .. 40 loop > Sss:=Fnmis-Si(Ijk); > if Sss<0.0 then > goto Label_1; > end if; > end loop; -- IJK > <<Label_1>> null; > > Before the loop Ijk is 0, after the loop Ijk is still 0. Huh? Why? Ijk does not even exist before or after the loop -- the "for Ijk" *declares* it. This is different from the way Pascal works. You didn't show your whole example, but I guess you declared another variable called Ijk outside the loop, initialized it to 0, and then never modified it again. A good Ada compiler will warn you about this situation, presuming you turn on warnings. IMHO, hiding is evil. If I were the boss, the inner Ijk would not hide the outer one, and the attempted reference to the inner one would be ambiguous and therefore illegal. >... I > replaced Ijk with temp variable and put Ijk := temp before goto and > it solved the problem, but why we can't have final value when we break > out of the loop? What's the logic behind this language behaviour? So I can be constant inside the loop. The way to think of it is that a new constant called I is created and destroyed *each* time through the loop. But as you can see, it backfires if you're used to the way Pascal works. Actually, doesn't the Pascal rule say that the value of I is *undefined* after a for loop? It's been a long time since I used Pascal... > Also when I try to debug this in GVD I can see Ijk variable, but not Sss > (it's a global variable described in outer procedure). I see following > message in the bottom window: > > (gdb) print Sss > Cannot access memory at address 0x24803ec > > How to look up these variables? I see that sort of thing all the time from gdb. I don't know what you can do, except complain to your compiler vendor. - Bob ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 16:17 ` Robert A Duff @ 2003-05-30 16:46 ` Bill Findlay 2003-05-30 16:51 ` Bill Findlay 1 sibling, 0 replies; 19+ messages in thread From: Bill Findlay @ 2003-05-30 16:46 UTC (permalink / raw) On 30/5/03 17:17, in article wcc1xyg9zoa.fsf@shell01.TheWorld.com, "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote: > > Actually, doesn't the Pascal rule say that the value of I is *undefined* > after a for loop? It's been a long time since I used Pascal... The controlled variable is undefined on exhaustion of the iteration range. -- Bill-Findlay chez blue-yonder.co.uk ("-" => "") ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 16:17 ` Robert A Duff 2003-05-30 16:46 ` Bill Findlay @ 2003-05-30 16:51 ` Bill Findlay 1 sibling, 0 replies; 19+ messages in thread From: Bill Findlay @ 2003-05-30 16:51 UTC (permalink / raw) On 30/5/03 17:17, in article wcc1xyg9zoa.fsf@shell01.TheWorld.com, "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote: >> ... I >> replaced Ijk with temp variable and put Ijk := temp before goto and >> it solved the problem, but why we can't have final value when we break >> out of the loop? What's the logic behind this language behaviour? > > So I can be constant inside the loop. The way to think of it is that a > new constant called I is created and destroyed *each* time through the > loop. > > But as you can see, it backfires if you're used to the way Pascal works. In BSI/ANSI/ISO Standard Pascal it is illegal to assign to the controlled variable inside the body of a for loop. -- Bill-Findlay chez blue-yonder.co.uk ("-" => "") ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 15:44 ada loops Roman V. Isaev 2003-05-30 16:00 ` Bill Findlay 2003-05-30 16:17 ` Robert A Duff @ 2003-05-30 17:25 ` Stephen Leake 2003-05-30 19:40 ` Robert A Duff 2003-06-05 5:14 ` Dave Thompson 2 siblings, 2 replies; 19+ messages in thread From: Stephen Leake @ 2003-05-30 17:25 UTC (permalink / raw) rm@gunlab.com.ru (Roman V. Isaev) writes: > I've got bitten by this (code was translated from pascal by p2ada, so > please don't bash using goto): > > for Ijk in 1 .. 40 loop > Sss:=Fnmis-Si(Ijk); > if Sss<0.0 then > goto Label_1; > end if; > end loop; -- IJK > <<Label_1>> null; > > Before the loop Ijk is 0, after the loop Ijk is still 0. Huh? Why? You left out the first declaration of Ijk. You must actually have something like: procedure Foo is Ijk : Integer; begin for Ijk in 1 .. 40 loop Sss:=Fnmis-Si(Ijk); if Sss<0.0 then goto Label_1; end if; end loop; -- IJK <<Label_1>> null; end Foo; There are _two_ variables named Ijk; one in the Foo procedure, and one in the loop. The loop index variable is _not_ visible outside the loop. Inside the loop, it hides the outer declaration. I don't remember how Pascal did this; I suspect the loop variable was not a new declaration. In standard C++, the loop variable is a new declaration (as in Ada), but in early versions of C++, it wasn't. > I replaced Ijk with temp variable and put Ijk := temp before goto > and it solved the problem, but why we can't have final value when we > break out of the loop? What's the logic behind this language > behaviour? I'm not sure of all of the reasons (see the Ada Rationale for more). It may have to do with optimizations. > Also when I try to debug this in GVD I can see Ijk variable, but not > Sss (it's a global variable described in outer procedure). I see > following message in the bottom window: > > (gdb) print Sss > Cannot access memory at address 0x24803ec That means you have a bug in your code, which is clobbering the stack or something. Or you have a version of gdb that is not Ada-aware. What OS and compiler are you using? -- -- Stephe ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 17:25 ` Stephen Leake @ 2003-05-30 19:40 ` Robert A Duff 2003-05-30 21:33 ` Pascal Obry ` (2 more replies) 2003-06-05 5:14 ` Dave Thompson 1 sibling, 3 replies; 19+ messages in thread From: Robert A Duff @ 2003-05-30 19:40 UTC (permalink / raw) Stephen Leake <Stephe.Leake@nasa.gov> writes: > That means you have a bug in your code, which is clobbering the stack > or something. Or you have a version of gdb that is not Ada-aware. What > OS and compiler are you using? There is no version of gdb that is Ada aware. - Bob ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 19:40 ` Robert A Duff @ 2003-05-30 21:33 ` Pascal Obry 2003-05-31 16:19 ` Robert A Duff 2003-05-31 16:29 ` Robert A Duff 2003-05-30 21:38 ` Simon Wright 2003-05-31 16:24 ` Oliver Kellogg 2 siblings, 2 replies; 19+ messages in thread From: Pascal Obry @ 2003-05-30 21:33 UTC (permalink / raw) Robert A Duff <bobduff@shell01.TheWorld.com> writes: > There is no version of gdb that is Ada aware. This is of course plain wrong ! Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://perso.wanadoo.fr/pascal.obry --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 21:33 ` Pascal Obry @ 2003-05-31 16:19 ` Robert A Duff 2003-05-31 16:29 ` Robert A Duff 1 sibling, 0 replies; 19+ messages in thread From: Robert A Duff @ 2003-05-31 16:19 UTC (permalink / raw) Pascal Obry <p.obry@wanadoo.fr> writes: > Robert A Duff <bobduff@shell01.TheWorld.com> writes: > > > There is no version of gdb that is Ada aware. > > This is of course plain wrong ! I was being somewhat sarcastic. ;-) Of course I am well aware of the version of gdb distributed with GNAT, and I use it. However, almost every time I use it in any serious way, it shows some confusion about Ada. For example, it thinks a parameter of type String is actually of type pointer-to-String. Often, it can't find objects that are (or should be) visible -- I'm not sure exactly what's going on, but I think it is confused about nested block statements, and nested procedures. Another example is that it often crashes when I try to call a procedure with anything but the simplest of parameter types. Calling procedures is a very useful feature of any debugger -- it allows you to print out data stuctures in a higher-level form than a plain listing of record fields and whatnot. But it only works half the time, in my experience. Another example: I have a generic package that is instantiated 20 times, and I want to call one of the procedures. Gdb will then ask me which of the 20 I meant. If it were truly Ada aware, it would know which one, based on the types of the actual parameters -- that's what the compiler knows how to do. The OP complained that gdb did something obviously wrong, and somebody responded saying it must be caused either by a bug in the Ada program that destroyed memory, or by using the wrong version of gdb. That's not my experience at all; the GNAT version gdb lies to me and/or crashes quite often, even when there are no memory-destroying bugs around the place. (Those bugs are quite rare in Ada, after all, given all the good array-bounds checking and whatnot.) So I stand by my claim: There is no version of gdb that is Ada aware. Gdb is a C debugger. The GNAT version understands some part of Ada, and it does improve over time, but it's still got a long way to go before it understands Ada as well as, say, the GNAT Ada compiler! Having said all that, I don't use debuggers very heavily. Usually just to get a stack traceback for an unhandled exception. I think it's usually better to try to understand the code I write, rather than to throw something together and then spend all day rummaging around in the debugger to see what's going on. - Bob ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 21:33 ` Pascal Obry 2003-05-31 16:19 ` Robert A Duff @ 2003-05-31 16:29 ` Robert A Duff 1 sibling, 0 replies; 19+ messages in thread From: Robert A Duff @ 2003-05-31 16:29 UTC (permalink / raw) Pascal Obry <p.obry@wanadoo.fr> writes: > Robert A Duff <bobduff@shell01.TheWorld.com> writes: > > > There is no version of gdb that is Ada aware. > > This is of course plain wrong ! Let me also say that my comment was not meant as an insult to the authors of the somewhat-Ada-aware version of gdb. Given that gdb was not designed with Ada in mind, they've done an admirable job of making it at least *partly* Ada aware. - Bob ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 19:40 ` Robert A Duff 2003-05-30 21:33 ` Pascal Obry @ 2003-05-30 21:38 ` Simon Wright 2003-05-30 21:51 ` chris.danx 2003-06-02 16:39 ` Stephen Leake 2003-05-31 16:24 ` Oliver Kellogg 2 siblings, 2 replies; 19+ messages in thread From: Simon Wright @ 2003-05-30 21:38 UTC (permalink / raw) Robert A Duff <bobduff@shell01.TheWorld.com> writes: > Stephen Leake <Stephe.Leake@nasa.gov> writes: > > > That means you have a bug in your code, which is clobbering the stack > > or something. Or you have a version of gdb that is not Ada-aware. What > > OS and compiler are you using? > > There is no version of gdb that is Ada aware. I don't understand, clearly you're making a point but I have no idea what it is. smaug.pushface.org[3]$ gnatgdb GNU gdb 5.1.1.gnat.3.15p Copyright 2002 Free Software Foundation, Inc. Ada Core Technologies version of GDB for GNAT Professional GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. See your support agreement for details of warranty and support. If you do not have a current support agreement, then there is absolutely no warranty for this version of GDB. Type show warranty for details. This GDB was configured as "i386-pc-linux". (interesting mix there, BTW! "3.15p", "GNAT Professional") ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 21:38 ` Simon Wright @ 2003-05-30 21:51 ` chris.danx 2003-05-31 6:40 ` Pascal Obry 2003-05-31 16:21 ` Robert A Duff 2003-06-02 16:39 ` Stephen Leake 1 sibling, 2 replies; 19+ messages in thread From: chris.danx @ 2003-05-30 21:51 UTC (permalink / raw) Simon Wright wrote: >>There is no version of gdb that is Ada aware. > > > I don't understand, clearly you're making a point but I have no idea > what it is. Perhaps it is that there is no Ada aware gdb, but there is a GNAT aware gdb? I tend to associate debuggers with implementations not languages, but I could be wrong... ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 21:51 ` chris.danx @ 2003-05-31 6:40 ` Pascal Obry 2003-05-31 16:21 ` Robert A Duff 1 sibling, 0 replies; 19+ messages in thread From: Pascal Obry @ 2003-05-31 6:40 UTC (permalink / raw) "chris.danx" <spamoff.danx@ntlworld.com> writes: > Perhaps it is that there is no Ada aware gdb, but there is a GNAT aware gdb? > I tend to associate debuggers with implementations not languages, but I could > be wrong... Well, gdb is the open source debugger distributed with GNAT, so of course it is Ada aware and support only GNAT. Other vendors distribute some other Ada-aware debuggers with their suite. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://perso.wanadoo.fr/pascal.obry --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 21:51 ` chris.danx 2003-05-31 6:40 ` Pascal Obry @ 2003-05-31 16:21 ` Robert A Duff 1 sibling, 0 replies; 19+ messages in thread From: Robert A Duff @ 2003-05-31 16:21 UTC (permalink / raw) "chris.danx" <spamoff.danx@ntlworld.com> writes: > Simon Wright wrote: > > >>There is no version of gdb that is Ada aware. > > I don't understand, clearly you're making a point but I have no idea > > what it is. > > Perhaps it is that there is no Ada aware gdb, but there is a GNAT aware > gdb? I tend to associate debuggers with implementations not languages, > but I could be wrong... No, I was not complaining that the gdb distributed with GNAT is GNAT-specific. That's to be expected. I was complaining that it is not as "Ada aware" as the Ada compiler. - Bob ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 21:38 ` Simon Wright 2003-05-30 21:51 ` chris.danx @ 2003-06-02 16:39 ` Stephen Leake 1 sibling, 0 replies; 19+ messages in thread From: Stephen Leake @ 2003-06-02 16:39 UTC (permalink / raw) Simon Wright <simon@pushface.org> writes: > Robert A Duff <bobduff@shell01.TheWorld.com> writes: > > > Stephen Leake <Stephe.Leake@nasa.gov> writes: > > > > > That means you have a bug in your code, which is clobbering the stack > > > or something. Or you have a version of gdb that is not Ada-aware. What > > > OS and compiler are you using? > > > > There is no version of gdb that is Ada aware. > > I don't understand, clearly you're making a point but I have no idea > what it is. Before I read Robert's follow-up, I thought we were getting into Artificial Intelligence; what does it mean for a program to be "aware" :). I agree with all of Robert's critiques of gdb's awareness of Ada. -- -- Stephe ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 19:40 ` Robert A Duff 2003-05-30 21:33 ` Pascal Obry 2003-05-30 21:38 ` Simon Wright @ 2003-05-31 16:24 ` Oliver Kellogg 2003-05-31 23:15 ` Preben Randhol 2 siblings, 1 reply; 19+ messages in thread From: Oliver Kellogg @ 2003-05-31 16:24 UTC (permalink / raw) Robert A Duff <bobduff@shell01.TheWorld.com> wrote in wccadd49qb2.fsf@shell01.TheWorld.com... > > There is no version of gdb that is Ada aware. At the risk of sounding like an ACT spokesperson (which I'm not), how about ftp://sources.redhat.com/pub/gdb/contrib/gnat/gdb-5.3-act-2003-02-25.tgz HTH Oliver Kellogg ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-31 16:24 ` Oliver Kellogg @ 2003-05-31 23:15 ` Preben Randhol 0 siblings, 0 replies; 19+ messages in thread From: Preben Randhol @ 2003-05-31 23:15 UTC (permalink / raw) Oliver Kellogg wrote: > > Robert A Duff <bobduff@shell01.TheWorld.com> wrote in > wccadd49qb2.fsf@shell01.TheWorld.com... >> >> There is no version of gdb that is Ada aware. > > At the risk of sounding like an ACT spokesperson (which I'm not), > how about > > ftp://sources.redhat.com/pub/gdb/contrib/gnat/gdb-5.3-act-2003-02-25.tgz http://libre.act-europe.fr/GDB/ -- Preben Randhol http://www.pvv.org/~randhol/ ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-05-30 17:25 ` Stephen Leake 2003-05-30 19:40 ` Robert A Duff @ 2003-06-05 5:14 ` Dave Thompson 2003-06-05 18:15 ` Stephen Leake 1 sibling, 1 reply; 19+ messages in thread From: Dave Thompson @ 2003-06-05 5:14 UTC (permalink / raw) On 30 May 2003 13:25:31 -0400, Stephen Leake <Stephe.Leake@nasa.gov> wrote: [for variable local to loop] > I don't remember how Pascal did this; I suspect the loop variable was > not a new declaration. In standard C++, the loop variable is a new > declaration (as in Ada), but in early versions of C++, it wasn't. > Not exactly. In C++ you have an explicit choice: 1) if you write e.g. for( i = 0; i < 10; i++ ) ... it uses an existing variable (which must be) already available (declared). 2) if you write e.g. for( int i = 0; i < 10; i++ ) ... it creates a new variable. But what happens thereafter varies: 2A) in pre-standard C++ (aka ARM) this declaration remains in scope (and the variable valid) after the loop, to the end of the containing { } block -- so you can't declare another variable (or anything) with the same name, in particular you can't do another for ( int i = 0 ...; 2B) in standard C++(88) it is declared and exists only to the end of the loop. In all cases, you need to match the type of the loop variable to the range of values assigned; this isn't determined for you automatically, nor checked for overflow (in practice, theoretically it's allowed). C99, BTW, adds to C the 2B variant. - David.Thompson1 at worldnet.att.net ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: ada loops 2003-06-05 5:14 ` Dave Thompson @ 2003-06-05 18:15 ` Stephen Leake 0 siblings, 0 replies; 19+ messages in thread From: Stephen Leake @ 2003-06-05 18:15 UTC (permalink / raw) Dave Thompson <david.thompson1@worldnet.att.net> writes: > On 30 May 2003 13:25:31 -0400, Stephen Leake <Stephe.Leake@nasa.gov> > wrote: > [for variable local to loop] > > I don't remember how Pascal did this; I suspect the loop variable was > > not a new declaration. In standard C++, the loop variable is a new > > declaration (as in Ada), but in early versions of C++, it wasn't. > > > Not exactly. In C++ you have an explicit choice: > > 1) if you write e.g. for( i = 0; i < 10; i++ ) ... it uses an existing > variable (which must be) already available (declared). > > 2) if you write e.g. for( int i = 0; i < 10; i++ ) ... it creates a > new variable. Right, sorry. I forgot the details. Fortunately, I'm not writing much C++ code these days :). -- -- Stephe ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2003-06-05 18:15 UTC | newest] Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-05-30 15:44 ada loops Roman V. Isaev 2003-05-30 16:00 ` Bill Findlay 2003-05-30 16:17 ` Robert A Duff 2003-05-30 16:46 ` Bill Findlay 2003-05-30 16:51 ` Bill Findlay 2003-05-30 17:25 ` Stephen Leake 2003-05-30 19:40 ` Robert A Duff 2003-05-30 21:33 ` Pascal Obry 2003-05-31 16:19 ` Robert A Duff 2003-05-31 16:29 ` Robert A Duff 2003-05-30 21:38 ` Simon Wright 2003-05-30 21:51 ` chris.danx 2003-05-31 6:40 ` Pascal Obry 2003-05-31 16:21 ` Robert A Duff 2003-06-02 16:39 ` Stephen Leake 2003-05-31 16:24 ` Oliver Kellogg 2003-05-31 23:15 ` Preben Randhol 2003-06-05 5:14 ` Dave Thompson 2003-06-05 18:15 ` Stephen Leake
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox