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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32cfbb718858528b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-09 10:47:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsfeed0.news.atl.earthlink.net!news.atl.earthlink.net!news.mindspring.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Commercial C To Ada 95 compiler Date: Sun, 09 Jun 2002 10:49:17 -0700 Organization: AdaWorks Software Engineering Message-ID: <3D03951D.B0A476ED@adaworks.com> References: <3D002D11.CC706952@adaworks.com> <4519e058.0206071148.9b87acf@posting.google.com> <3D0116F3.7254E263@despammed.com> <3D018106.6080004@worldnet.att.net> <3D022877.B3B5CD3A@adaworks.com> <3D0263D2.1050604@worldnet.att.net> Reply-To: richard@adaworks.com NNTP-Posting-Host: 41.b2.41.a3 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 9 Jun 2002 17:46:43 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:25607 Date: 2002-06-09T17:46:43+00:00 List-Id: Jim Rogers wrote: > Richard Riehle wrote: > > > Jim Rogers wrote: > > > > > >>One simple example is indexing past the end of an array. > >>C compilers simply will not catch this problem. Ada compilers will. > >> > > > > Actually, note that the following program that indexes off the end > > of an array will compile in Ada. > > > > procedure Index_Past_The_End is > > type Vector is array(Positive range <>) of Integer; > > The_Vector : Vector (1..100) := (others => 0); > > begin > > for I in The_Vector'First .. The_Vector'Last + 1 > > loop > > null; > > end loop; > > end Index_Past_The_End; > > Ah, but you are not indexing the array. You are merely creating > a range based upon the array index range. You can iterate through > any range you want. You will get a compiler error when you > attempt to access (index) an array "element" beyond either end of > the array. > > The_Vector(The_Vector'Last + 1) := 10; > > Jim Rogers You are correct about this example Jim. It is also true that in my original example, the null statement does not cause a run-time error. I used the null because I was being lazy. However, in my other post where I suggested adding, The_Vector(I) := 10; the code is doing an indexed operation and will, at execution, attempt to index past the end of the array. This will raise a constraint_error at run-time that is not detected by the compiler. Richard Riehle