From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e30b6046584172fe X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Help: Dynamic-size arrays using record discriminant. Date: 1998/10/13 Message-ID: #1/1 X-Deja-AN: 400736122 References: <361E3D0C.41AAC13B@classnet.co.il> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1998-10-13T00:00:00+00:00 List-Id: In article <361E3D0C.41AAC13B@classnet.co.il> Alon Matas writes: -- I have this problem: -- There is a record with a discriminant (and a default value to the -- discriminant). The record contains a constrained array, and the range -- of the array depends on the discriminant. For example: -- The question is how do I change the array size (i.e, the discriminant -- value) WITHOUT loosing its current content... Easy, make the discriminant an element of the record. If you insist on being clever, do the following. First insure that your compiler actually allocates the maximum size necessary for the largest possible value of the object. Next, declare a type which overlays exactly the discriminated record type, but where the discriminant is replaced by a array component. Now use address clauses to do the aliasing and do what you want... Or you can just realize that some compilers will create the objects in a way that requires hidden heap allocations and pointers, and from the fact that your declarations: type ARRAY_TYPE is array (INTEGER range <>) of NATURAL; type RECORD_TYPE (SIZE: INTEGER:= 5) is record VECTOR: ARRAY_TYPE (1..SIZE); end record; don't lead to a compiler warning, that you are using such an implementation. So not only is it necessary to copy the old value to the new object, but a clever compiler will (depending on how you write the code) optimize away the "extra" copy. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...