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!postnews.google.com!k70g2000cwa.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Loop parameter type Date: 25 Sep 2006 17:12:33 -0700 Organization: http://groups.google.com Message-ID: <1159229553.123082.229930@k70g2000cwa.googlegroups.com> References: <20060925105627.GA14409@ws.max.zp.ua> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1159229558 24332 127.0.0.1 (26 Sep 2006 00:12:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Sep 2006 00:12:38 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k70g2000cwa.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:6736 Date: 2006-09-25T17:12:33-07:00 List-Id: Maxim Reznik wrote: > 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? > > I expect range 1 .. 10 is root_integer type, because of preference > root_integer over others integer types. > ARM states: "There is a preference for the primitive operators (and > ranges) of the root numeric types root_integer and root_real." Bob and Jeff have already explained why the types of J and K are of type Standard.Integer and not root_integer. You should also be aware that if J and K *were* root_integer, then you'd get two errors instead of one, because there is no predefined + operation whose left operand is Standard.Integer or Int, and whose right operand is root_integer. You're probably confusing this with universal integers. A universal integer can appear any place that *any* integer type is expected. But a value of type root_integer is *not* a universal integer and doesn't have that property. -- Adam