comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Curiosity about rage checking
Date: Thu, 7 Feb 2008 12:21:01 +0100
Date: 2008-02-07T12:21:01+01:00	[thread overview]
Message-ID: <1fo4kfkv5m8xt.uuhbb0mso1ik.dlg@40tude.net> (raw)
In-Reply-To: d72f0b00-f44d-4e10-be01-577beddcfbfc@j20g2000hsi.googlegroups.com

On Thu, 7 Feb 2008 02:36:01 -0800 (PST), framefritti@gmail.com wrote:

> Jean-Pierre Rosen ha scritto:
> 
>> framefritti@gmail.com a �crit :
>>> [..]
>>>
>>> My question is: is an Ada compiler allowed to move the check outside
>>> the loop?
>>
>> This question is addressed in the (in)famous paragraph 11.6. If you
>> don't understand exactly what it says, don't worry, you are not alone...
>>
>> But the important issue is that compilers are unlikely to perform that
>> optimization. Why? Because optimization is a matter of improving what's
>> normally used. And any decent Ada programmer should write that loop as:
>>
>> for I in X'range loop...
>>
>> Where the optimization becomes trivial
> 
> I agree, and that is what I usually do, but there are times when you
> want to loop
> over a limited part of X or not in the usual order (e.g., transposing
> a matrix stored (for whatever
> reason) as a one-dimensional array)

You still can follow that path:

Assuming that X is array (Integer range <>) of something real (:-)):

   subtype Domain is Integer range X'Range;
   subtype Subdomain is Domain range Domain'First + 1..Domain'Last - 1;
begin
   for I in Subdomain loop
      X (I) := 0.0; -- The compiler should know that I is from X'Range
   end loop;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-02-07 11:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-07  8:17 Curiosity about rage checking framefritti
2008-02-07  8:45 ` Maciej Sobczak
2008-02-07  9:55 ` Jean-Pierre Rosen
2008-02-07 10:36   ` framefritti
2008-02-07 11:21     ` Dmitry A. Kazakov [this message]
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