comp.lang.ada
 help / color / mirror / Atom feed
* Loop parameter type
@ 2006-09-25 10:56 Maxim Reznik
  2006-09-25 11:50 ` Stuart
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Maxim Reznik @ 2006-09-25 10:56 UTC (permalink / raw)


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."

In this case both 7 and 11 lines need explicit type conversion.

Why GNAT says type of K is Standard.Integer type?

Thank you
-- 
Maxim Reznik




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-09-26  0:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox