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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Array Index: substitute integer with enumeration Date: Thu, 4 Jun 2020 19:49:54 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 4 Jun 2020 17:49:55 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="a6c394dce66182c2e43db968fb083392"; logging-data="17737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HlsT28LyaE8VU21AHS5K069R1AUrOfXM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 Cancel-Lock: sha1:mrJegSIdSAFQefICJC0SO9s2YEE= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58960 Date: 2020-06-04T19:49:54+02:00 List-Id: On 6/4/20 6:54 PM, hreba wrote: > > function To_Spherical (p: Point) return Point is >   pc: Cart_Point:= p; > begin >   return >     ( Sqrt(pc(x)**2 + pc(y)**2 + pc(z)**2),    -- r >       Arctan(p(y)/p(x)),            -- phi >       ... >     ) > end To_Spherical. > > My questions are now: > > 1. Does the initialization of pc involve any copying at run time? 1. If you can get your code to compile, you can check the object code to see. The only reason for worrying about this is if it causes Storage_Error or failure to meet your quantitative timing requirements. Since you haven't tried it, you don't know that will happen, so there's no reason for concern. Seems to me that with a design like package Cartesian is type Point is record X : Float := 0.0; Y : Float := 0.0; Z : Float := 0.0; end record; -- Operations of Point generic type Client_Point is private; with function To_Cartesian (P : Client_Point) return Point; with function To_Client (P : Point) return Client_Point; package Client is -- Operations of Client_Point end Client; end Cartesian; type Point is record R : Float := 0.0; Phi : Float := 0.0; Theta : Float := 0.0; end record; function To_Cartesian (P : Point) return Cartesian.Point; function To_Spherical (P : Cartesian.Point) return Point; package Spherical is new Cartesian.Client (Client_Point => Point, To_Cartesian => To_Cartesian, To_Client => To_Spherical); copying would not be a concern. -- Jeff Carter "When Bell Labs were invited to evaluate C against the DoD requirements [for Ada], they said that there was no chance of C meeting the requirements of readability, safety, etc. for which we were striving, and that it should not even be on the list of evaluated languages." William Whitaker 116