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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,453ed54f02292eea,start X-Google-Attributes: gid103376,public From: gisle@spurv.ii.uib.no (Gisle S�lensminde) Subject: Re: Simple Ada question Date: 2000/05/16 Message-ID: #1/1 X-Deja-AN: 624074861 Content-Transfer-Encoding: 8bit References: <8f8fm5$de5$1@news.uit.no> Organization: University of Bergen, Norway Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-05-16T00:00:00+00:00 List-Id: In article <8f8fm5$de5$1@news.uit.no>, Reinert Korsnes wrote: > > >Given the following simple test program which I try using gnat-3.12p-11 >under Linux : > >----------------------------------------------------------------------- > >with Ada.Numerics.Generic_Elementary_Functions,Text_IO; >procedure test1 is > package Flt_Io is new Text_IO.Float_Io (Float); > package Int_Io is new Text_IO.Integer_Io (Integer); > package E_F is new > Ada.Numerics.Generic_Elementary_Functions (Float); > use E_F,Flt_Io,Int_Io; > n,I : Integer; > x : Float; > begin > x := 10.0; > n := 50000; > for I in 1 .. 10_000_000 loop > x := x + Float(I)/1000_000.0; > x := x*0.5 + 1.0 + sin(x)*cos(x) + sin(x) + cos(x) + > sin(x)*sin(x) + cos(x)*cos(x); > if I mod n = 0 then > Put(I); Put (x,3,4,0);Put(Integer(Float'Floor(x))); > Text_IO.New_Line (1); > end if; > end loop; >end; >------------------------------------------------------------------------ > >I get from "gnatmake test1.adb": > >gnatgcc -c test1.adb >test1.adb:8:06: warning: "I" is never assigned a value >gnatbind -x test1.ali >gnatlink test1.ali > In Ada, the index variable in the loop is implicitly defined in the for loop statment, and only in the scope the for-loop defines. That means that the index variable overrides the I variable you decleard in the declaration section of the main procedure. The following code is legal ada. with ada.text_io; procedure test is begin for I in 1 .. 100 loop ada.text_IO.put_line(integer'image(I)); end loop; end; -- -- Gisle S�lensminde ( gisle@ii.uib.no ) ln -s /dev/null ~/.netscape/cookies