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-Thread: 103376,4066f0f220a75baf X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Loop parameter type Date: 25 Sep 2006 12:32:13 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <20060925105627.GA14409@ws.max.zp.ua> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1159201933 3853 192.74.137.71 (25 Sep 2006 16:32:13 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 25 Sep 2006 16:32:13 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news2.google.com comp.lang.ada:6727 Date: 2006-09-25T12:32:13-04:00 List-Id: Maxim Reznik writes: > Hi, All > > Please help me understand Ada name resolution rules for > loop parameter specification. > > Consider follow code: > > 1: procedure Test is > 2: type Int is range 0 .. 1000; > 3: C : Integer := 0; > 4: C_Int : Int := 0; > 5: begin > 6: for J in 1 .. 10 loop > 7: C := C + J; > 8: end loop; > 9: > 10: for K in 1 .. 10 loop > 11: C_Int := C_Int + K; > 12: end loop; > 13: end Test; > > gcc -c test.adb > test.adb:11:22: invalid operand types for operator "+" > test.adb:11:22: left operand has type "Int" defined at line 2 > test.adb:11:22: right operand has subtype of "Standard.Integer" defined > at line 10 > > GNAT complains at line 11, but line 7 seems Ok. Why? The rule is in RM-3.6(18). J and K above are both of type Integer, not Int. IMHO it's a kludge, and you should not rely on it. Say "for I in Integer range 1..10" or "for I in Int range 1..10" or whatever. - Bob