comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Loop parameter type
Date: 25 Sep 2006 12:32:13 -0400
Date: 2006-09-25T12:32:13-04:00	[thread overview]
Message-ID: <wccejtzzz3m.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 20060925105627.GA14409@ws.max.zp.ua

Maxim Reznik <reznikmm@front.ru> 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



  parent reply	other threads:[~2006-09-25 16:32 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 [this message]
2006-09-25 19:08 ` Jeffrey R. Carter
2006-09-26  0:12 ` Adam Beneschan
replies disabled

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