comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Loop parameter type
Date: 25 Sep 2006 17:12:33 -0700
Date: 2006-09-25T17:12:33-07:00	[thread overview]
Message-ID: <1159229553.123082.229930@k70g2000cwa.googlegroups.com> (raw)
In-Reply-To: 20060925105627.GA14409@ws.max.zp.ua

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




      parent reply	other threads:[~2006-09-26  0:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-25 10:56 Loop parameter type Maxim Reznik
2006-09-25 11:50 ` Stuart
2006-09-25 16:32 ` Robert A Duff
2006-09-25 19:08 ` Jeffrey R. Carter
2006-09-26  0:12 ` Adam Beneschan [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox