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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!news.etla.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Arrays in Ada 2012 Date: Tue, 6 Jun 2017 15:56:00 -0500 Organization: JSA Research & Innovation Message-ID: References: <35c6ac5a-3295-4fa4-8545-ca76c113dde4@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1496782561 2009 24.196.82.226 (6 Jun 2017 20:56:01 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 6 Jun 2017 20:56:01 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:46907 Date: 2017-06-06T15:56:00-05:00 List-Id: "AdaMagica" wrote in message news:e4066890-cc2c-496e-a6ce-f9a9ef9dc3f5@googlegroups.com... > Am Dienstag, 6. Juni 2017 13:47:06 UTC+2 schrieb Anatoly Chernyshev: >> Hello everyone, >> >> Consider the following nice Ada 2012 construct: >> >> -- >> procedure test is >> type a1 is array(1..35,1..35,1..35,1..35,1..35,1..35) of >> long_long_integer; >> ab:a1; >> cnt:long_long_integer:=0; >> begin >> for e of ab loop >> cnt:=cnt+1; >> e:=cnt; >> end loop; >> end test; >> -- >> >> Is there a way (e.g. some attribute) to find the indices of the array >> for a current e within the cycle above? > > No, there are no attributes giving the current indices. You have to use > the nested loops form if you need the indices. More than likely, the compiler generates code that doesn't even know the indices in question, as doing address math is much cheaper than redoing an address calculation on each loop. (This is an optimization called "strength reduction" that some compilers can do with the conventional loop form, but it's better to start out with the reduced code.) That is, the loop will be generated as something like: [The following is pseudo code that's not all legal Ada code, but I hope you get the idea...] Current := AB(AB'First(1), ..., AB'First(6))'Address; Finish := AB(AB'Last(1), ..., AB'Last(6))'Address; while Current <= Finish loop cnt:=cnt+1; Current.all :=cnt; Current := Current + Long_Long_Integer'Size/Storage_Unit; end loop; No indices anywhere, and having a way to provide them would prevent the optimization (or would be very complicated in the general case). Randy.