comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: Q: Trouble creating array and discriminated type
Date: Sat, 21 Jan 2017 21:12:36 -0800 (PST)
Date: 2017-01-21T21:12:36-08:00	[thread overview]
Message-ID: <ecdfed06-8eb6-419c-9fa2-c10a0eb1d0b5@googlegroups.com> (raw)
In-Reply-To: <3b436d6a-7704-47cf-8f6f-d974771bea63@googlegroups.com>

On Saturday, January 21, 2017 at 12:05:34 PM UTC-5, Stephen Leake wrote:
> 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.

Since you are trying to learn Ada, it is worth noting that you can declare subtypes for the index ranges, since you seem to have maximums that are set when you run the program:

 subtype Offset is Positive range 1..Offset_Maximum;
 subtype Record_type is Positive range 1..Record_Maximum;
 -- or you can have one subtype if the bounds are the same...

 type Ephemeris_Data (Offset := Offset_Maximum, Record_type := Record_Maximum)
    is tagged record...

 Now even if the compiler allocates the maximum size for each object, that's likely to be fine with you.  Note that there is no requirement in Ada for the values Offset_Maximum and Record_Maximum to be static.  You can read them in or get them from the keyboard, and no one will complain.

One other "learning" type point.  I always used to teach students that if they needed something that eventually made sense as a standalone package, nest it within the main program until you get it running, then move toward greater abstraction.  In this particular case, your complaints about package initialization seem to indicate that the package want to create should actually be a generic package, instantiated inside the main program in a nested scope.  I don't really expect you to understand what I just said, until you actually have a working program and transform it to have a separately compiled generic package. ;-)





  reply	other threads:[~2017-01-22  5:12 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
2017-01-22  5:12   ` Robert Eachus [this message]
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