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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9c3095e7116890a3 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: loop and block question Date: 1997/01/29 Message-ID: #1/1 X-Deja-AN: 213053917 references: <1997Jan29.171423.3481@news.nbi.dk> organization: The World Public Access UNIX, Brookline, MA keywords: Ada, loop statement itentifier, block statement, GNAT newsgroups: comp.lang.ada Date: 1997-01-29T00:00:00+00:00 List-Id: In article <1997Jan29.171423.3481@news.nbi.dk>, Jacob Sparre Andersen wrote: >GNAT will not compile the inserted procedure, where I, in two different block >statements, declare two loops with the same loop statement identifier. GNAT is correct. See RM-5.1(11). Statement_identifier means a goto-label, or a block name, or a loop name, according to the syntax rules. >Is that because > > a) loop statement identifiers are globally known? Not completely global, but more global than a single block. All loop names have to be unique, within a single procedure (for example). > b) identifiers declared within a block statement are globally known? No, just statement_identifiers. > c) that's how it is? Yes, that's how it is. ;-) > d) GNAT has an annoying feature? Perhaps it's annoying, but it's what the RM says. The rule is the same as in Ada 83. I guess the reasoning is to avoid confusion. For goto labels, that makes sense. For loop and block names, I'm not so sure -- perhaps "annoying restriction" is appropriate. On the other hand, consider: procedure P is begin Loop_Name: loop declare ... begin Loop_Name: loop -- Illegal ... exit Loop_Name when ...; -- Would be confusing, if legal. end loop; end; end loop; end P; 5.1(11) prevents the above, although I'm inclined to believe that hiding in general is to blame. One should never be allowed to hide an outer thing with an inner thing, IMHO. Or, if you think hiding is useful, an explicit "hide" statement should be in the language, rather than letting you accidentally hide things just be declaring a name. Your example doesn't involve hiding, and so seems reasonable to me. >I have read sections 5.5 (Loop Statements) and 5.6 (Block Statements), but >they didn't make me much wiser. Look at 5.1. In writing the RM, we tried to avoid writing the same rule more than once, because we feared the consequences of multiple rules not being in synch (the normal danger of duplicating code -- remember, the RM was undergoing heavy maintenance during that time). The problem is that it makes it hard to find things -- you look at 5.5 about loop names, and you don't know that we decided to hide the relevant rule in 5.1, which is about the more general concept of statement_names (among other things). >-- 8. Some_Loop_Name: >-- | >-- >>> "Some_Loop_Name" conflicts with label at line 18 - Bob P.S. I wrote RM-5.1(11), and I also wrote the code in GNAT that gives this error message. So you can blame me, personally, for your troubles. ;-) P.P.S. I think 5.1(11) adds a lot of unnecessary complexity to an Ada compiler. Ada 83 should have simply required pre-declaration of labels, as does Pascal. Gotos are not so commonly used that the burden of writing an extra label decl is onerous.