comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Q: Trouble creating array and discriminated type
Date: Sat, 21 Jan 2017 09:05:33 -0800 (PST)
Date: 2017-01-21T09:05:33-08:00	[thread overview]
Message-ID: <3b436d6a-7704-47cf-8f6f-d974771bea63@googlegroups.com> (raw)
In-Reply-To: <83409c51-59d3-4205-9eeb-5467de09f069@googlegroups.com>

On Friday, January 20, 2017 at 4:55:52 PM UTC-6, b.mcgui...@gmail.com wrote:

Addressing the second problem:

>   type Ephemeris_Data (Offset_Maximum, Record_Maximum : Positive) is tagged record

If you add defaults to the discriminants, Ada will let you declare an uninitialized object. On the other hand, it might try to allocate all of memory for it, in which case the access object is a better solution.

 
> JPL_Data : access JPL_Ephemeris.Ephemeris_Data;
> 
> procedure initialize (header_file_pathname, coefficient_file_pathname : String) is
> begin
>   Real_IO.Open (File, Real_IO.In_File, coefficient_file_pathname);
>   JPL_Data := JPL_Ephemeris.Make (header_file_pathname)'Access;

This should be:

   JPL_Data := new JPL_Ephemeris.Ephemeris_Data'(JPL_Ephemeris.make (file);

It might be better to not declare this object in the package, but rather in the subprogram where it is needed; then you could avoid the access type. On the other hand, if it is shared among many subprograms, this is the right way.

--  Stephe


  parent reply	other threads:[~2017-01-21 17:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 22:55 Q: Trouble creating array and discriminated type b.mcguinness747
2017-01-20 23:48 ` gautier_niouzes
2017-01-21  7:23 ` Simon Wright
2017-01-21  9:41 ` Jeffrey R. Carter
2017-01-21 17:05 ` Stephen Leake [this message]
2017-01-22  5:12   ` Robert Eachus
2017-01-23  8:02   ` G.B.
2017-01-23  8:19     ` Simon Wright
2017-01-21 18:55 ` b.mcguinness747
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox