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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1a6e940e9297b109,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!s13g2000prd.googlegroups.com!not-for-mail From: "framefritti@gmail.com" Newsgroups: comp.lang.ada Subject: Curiosity about rage checking Date: Thu, 7 Feb 2008 00:17:35 -0800 (PST) Organization: http://groups.google.com Message-ID: <29e89783-8802-474e-b3c7-9721407ce42e@s13g2000prd.googlegroups.com> NNTP-Posting-Host: 158.110.28.116 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1202372256 30606 127.0.0.1 (7 Feb 2008 08:17:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 7 Feb 2008 08:17:36 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s13g2000prd.googlegroups.com; posting-host=158.110.28.116; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 Galeon/1.2.11 (X11; Linux i686; U;) Gecko/20030708,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19723 Date: 2008-02-07T00:17:35-08:00 List-Id: Dear *, this morning, while I was shaving myself, a curiosity about array access checking in Ada came to my mind... Consider the following piece of code for I in A..B loop -- <--------------------+ Put_Line("Assigning entry for I=" & Integer'Image(I)); -- | -- | X(I) := 0; -- <== Access checking for this assignement could be moved here--+ end loop As explained in the fancy comment (I hope you are seeing it with a fixed-size font :-) the check for index overflow in the access to X could be done _outside_ the for loop, saving some computational effort. My question is: is an Ada compiler allowed to move the check outside the loop? Let me raise few objections myself 1. The saving is not very important But it comes for free (it seems to me). Moreover, the type of array access used above is (in my opinion) very common. 2. Moving the check outside the loop changes the program behaviour if, for example, X index ranges from 1 to 5, A=3 and B=6, with the check inside the loop 3 iterations are done (and 3 lines are printed), while with the check outside the loop no iteration is done. Therefore, the program behaves differently. However, the program is buggy anyway, and maybe we are not so interested in preserving the behaviour of wrong programs.... 3. It make debugging harder This is a good objection since the exception is raised _before_ (and sometimes much before) the error actually happens. Maybe one could use usual access checking during the debug phase, while keeping "optimized" checking in the production phase. Thank you 2#10_0000_0000#