From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Array Index: substitute integer with enumeration
Date: Thu, 4 Jun 2020 19:49:54 +0200
Date: 2020-06-04T19:49:54+02:00 [thread overview]
Message-ID: <rbbc83$ha9$1@dont-email.me> (raw)
In-Reply-To: <hjsnauF9ikeU1@mid.individual.net>
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
next prev parent reply other threads:[~2020-06-04 17:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-04 16:54 Array Index: substitute integer with enumeration hreba
2020-06-04 17:49 ` Jeffrey R. Carter [this message]
2020-06-05 15:16 ` hreba
2020-06-05 17:15 ` Jeffrey R. Carter
2020-06-09 17:25 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox