From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8b8f4ad9d302b143 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-30 10:35:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: ada loops Date: 30 May 2003 13:25:31 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1054316494 8237 128.183.235.92 (30 May 2003 17:41:34 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 30 May 2003 17:41:34 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.ada:38128 Date: 2003-05-30T17:41:34+00:00 List-Id: 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 > <> 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 <> 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