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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8d472879e3f609e0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-05 18:24:10 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Case sensitivity (was Re: no title) From: James Rogers References: <20619edc.0306021018.6ee4dd09@posting.google.com> <1054649187.11497@master.nyc.kbcfp.com> <20619edc.0306031034.6a2f5f25@posting.google.com> <1054666439.685312@master.nyc.kbcfp.com> <1054735867.264510@master.nyc.kbcfp.com> <1054748714.868159@master.nyc.kbcfp.com> Message-ID: User-Agent: Xnews/5.04.25 Date: Fri, 06 Jun 2003 01:24:09 GMT NNTP-Posting-Host: 12.86.37.88 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1054862649 12.86.37.88 (Fri, 06 Jun 2003 01:24:09 GMT) NNTP-Posting-Date: Fri, 06 Jun 2003 01:24:09 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:38743 Date: 2003-06-06T01:24:09+00:00 List-Id: Stephen Leake wrote in news:ullwgh20s.fsf@nasa.gov: > Hyman Rosen writes: > >> If I'm not mistaken, the following code *does* compile. >> >> for index in my_array'range loop >> declare >> Index : integer := 27; >> begin >> if my_array ( Index ) > current_maximum >> then >> current_maximum := my_array ( index ); >> Index := index; >> end if; >> end; >> end loop; > > Yes, it does, and it has a bug. If the language was not > case-sensitive, the bug would be easier to see. > When I place this snippet into a real program I do get a clean compile. The program does generate an exception at run time on the first loop iteration. with Ada.Text_Io; use Ada.Text_Io; procedure Badloop is type Foo_Array is array (1 .. 10) of Integer; My_Array : Foo_Array := (10, 9, 8, 7, 6, 5, 4, 3, 2, 1); Current_Maximum : Integer := 1; begin for Index in My_Array'range loop declare Index : Integer := 27; begin if My_Array ( Index ) > Current_Maximum then Current_Maximum := My_Array ( Index ); Index := Index; end if; end; end loop; Put_Line("Current_Maximum:" & Integer'Image(Current_Maximum)); end Badloop; Note that the above bad code is not solved by making your language case sensitive. A C example: for(i = 0; i < 9; ++i) { int i = 27; if (My_Array[i] > currentMaximum) { currentMaximum = My_Array[i]; i = i; } { The C compiler will compile this program without error. The difference is that the C compiler will allow you to access beyond the end of the array with no complaints. In fact, this program will run for an at least one full iteration, and possibly more. Ada still ends up being safer than C because it prevents array bounds violations at run-time. Jim Rogers