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 09:17:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!out.nntp.be!propagator2-sterling!news-in-sterling.newsfeed.com!news-out.visi.com!petbe.visi.com!uunet!ash.uu.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: ada loops Date: 30 May 2003 12:17:41 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1054311461 22894 199.172.62.241 (30 May 2003 16:17:41 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 30 May 2003 16:17:41 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:38113 Date: 2003-05-30T12:17:41-04: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? 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