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: 9 Sep 92 05:26:34 GMT From: munnari.oz.au!yoyo.aarnet.edu.au!huon.itd.adelaide.edu.au!cs.adelaide.edu .au!andrewd@uunet.uu.net (Andrew Dunstan) Subject: Re: Generics? Message-ID: <18k1uaINN6su@huon.itd.adelaide.edu.au> List-Id: In article <6978@stan.xx.swin.oz.au>, rob@saturn.cs.swin.OZ.AU (Rob Allen) writ es: |> tp923021@jarrah.canberra.edu.au (Ben Elliston) writes: |> >I've since moved onto making an array a generic type (such as this): |> >GENERIC |> >Type Index IS (<>); |> >[..] |> >Type Stack_Array IS Array(Index) of Character; |> |> >Type Stack_Type IS RECORD |> > Data_Store: Stack_Array; |> > Pointer: Natural; |> >END RECORD; |> |> >As it stands now, it seems that since the "pointer" variable (which |> >indicates the current "highwater" mark of the array) is a natural, that |> >Ada won't allow a natural to access an array indexed by some unknown |> >(generic) type. [..] |> If however you decide to keep Pointer as a Natural where 1 corresponds to |> the first element then always use it as |> X.Data_Store(Index'val(X.Pointer - 1 + Pos_1st)) |> where |> Pos_1st : constant := Index'pos(Index'first); |> is to account for the likelihood that the actual Index is an arbitrary |> subtype of a discrete type. Using this approach the 'full' test is |> X.Pointer = Index'length |> Though none of the above code has been checked, I hope that helps. rob I'd like to see the code from which this is taken. If what is really wanted is a stack, why is the index of the stack array a generic parameter? It seems to me that the only generic type parameter for a stack type should be the type stored - after all, the stack might not be implemented as an array at all. I agree that Rob Allen's answer to the question is correct, but I still want to know why the above is being attempted. -- ####################################################################### # Andrew Dunstan # There's nothing good or bad # # Department of Computer Science # but thinking makes it so. # # University of Adelaide # # # South Australia # - Shakespeare # # net: andrewd@cs.adelaide.edu.au # # #######################################################################