comp.lang.ada
 help / color / mirror / Atom feed
From: "framefritti@gmail.com" <framefritti@gmail.com>
Subject: Curiosity about rage checking
Date: Thu, 7 Feb 2008 00:17:35 -0800 (PST)
Date: 2008-02-07T00:17:35-08:00	[thread overview]
Message-ID: <29e89783-8802-474e-b3c7-9721407ce42e@s13g2000prd.googlegroups.com> (raw)

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#



             reply	other threads:[~2008-02-07  8:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-07  8:17 framefritti [this message]
2008-02-07  8:45 ` Curiosity about rage checking Maciej Sobczak
2008-02-07  9:55 ` Jean-Pierre Rosen
2008-02-07 10:36   ` framefritti
2008-02-07 11:21     ` Dmitry A. Kazakov
2008-02-07 15:57   ` Adam Beneschan
2008-02-07 16:45 ` Robert A Duff
2008-02-07 16:54 ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox