From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 23 Sep 93 23:51:54 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: null unconstrained arrays vs generic formal types Message-ID: List-Id: In article <23SEP199311043613@bambam.gsfc.nasa.gov> nbssal@bambam.gsfc.nasa.gov (Stephe Leake) writes: > So, does Ada 9x fix this by relaxing LRM 12.3.4(5)? Does anyone > have an alternate solution? It took me a while to recognize why you had a problem. (Even if you quoted my favorite paragraph number in Ada 83.) Ada 9X retains the same rule, although you could submit this as a comment on the standard during the balloting. Of course, the "right" solution might be to have generic formal subtypes. But I don't think you need any of that. In Ada 9X you could make the array type a generic formal derived type, but the real solution is to reorganize things so that you have a generic formal package: generic type Index_Base_Type is range <>; type Element_Type is range <>; -- why not private? Index_Last: Index_Base_Type; package Element_Arrays is subtype ZERO_INDEX_TYPE is range 0 .. Index_Last; subtype INDEX_TYPE is ZERO_INDEX_TYPE range 1 .. Index_Last; type INDEX_ARRAY_ELEMENT_TYPE is array (INDEX_TYPE range <>) of ELEMENT_TYPE; procedure Element_Get (Item : out ELEMENT_TYPE; Width : in Text_IO.FIELD); procedure Element_Put ( Item : in ELEMENT_TYPE; Width : in Text_IO.FIELD; Base : in Text_IO.NUMBER_BASE); ... end Element_Arrays; package Int_30_Arrays is new Element_Arrays(Integer, Integer, 30); -- for example... Now your generic array IO package looks like: with Text_IO; generic with package Elem_Arrays is new Element_Arrays(<>); package Unconstrained_Integer_1D is use Elem_Arrays; -- depending on your religion. :-) procedure Get (Item : out INDEX_ARRAY_ELEMENT_TYPE; Last : out ZERO_INDE X_TYPE); procedure Put (Item : in INDEX_ARRAY_ELEMENT_TYPE); end Unconstrained_Integer_1D; Of course you could put Element_Get and Element_Put elsewhere, but the principle is that you can pass two subtypes of the same type as generic parameters in Ada 9X by wrapping them in a generic package parameter. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...