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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a00006d3c4735d70 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-29 01:00:31 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!tar-atanamir.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: In-Out Parameters for functions Date: Thu, 29 Jan 2004 10:08:19 +0100 Message-ID: <9khh10pti0dn8gcp7f18ghptaifluj0fud@4ax.com> References: <1075159458.149886@master.nyc.kbcfp.com> <1075225041.167448@master.nyc.kbcfp.com> <1075303237.975898@master.nyc.kbcfp.com> NNTP-Posting-Host: tar-atanamir.cbb-automation.de (212.79.194.116) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1075366829 27615824 212.79.194.116 ([77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:5028 Date: 2004-01-29T10:08:19+01:00 List-Id: On Wed, 28 Jan 2004 10:20:37 -0500, Hyman Rosen wrote: >Dmitry A. Kazakov wrote: >> for I in A'Range loop >> Sum := Sum + A (I) + B (I - A'First + B'First); >> end loop; > >For code like this, I would expect the compiler to be >generating all sorts of induction variables. There's >never going to be a loop constant to hoist. The >generated code should look something like this (in C): > >n = A_Last - A_First + 1; >if (B_Last - B_First + 1 < n) raise Program_Error; >pa = &A[A_First]; >pb = &B[B_First]; >while (n-- > 0) sum += *pa++ + *pb++; This violates the evaluation order. It should be: sum += *pa++; sum += *pb++; risking to overflow (*) and less stable numerically. >In any case, the compiler would be free to rearrange its >calculations any way it likes as long as the results are >the same as doing them in the proper order. You managed to factor (I - A'First) out, this can be done without changing the evaluation order, fine. But what will you do for: for I in A'Range loop Sum := Sum + A (I) + B (I + B'First - A'First); end loop; >If the compiler >cannot determine that this is the case, then the code is >probably tricky enough such that doing it in the defined >order is helpful. My point is, I would leave that stuff to the compiler developers. I trust them more than me and my programmers! (:-)) ---- * and reviving the discussion about introducing ":+=" -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de