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: 2 Jul 91 13:06:27 GMT From: haven.umd.edu!uvaarpa!software.org!stluka@louie.udel.edu (Fred Stluka) Subject: Re: What should this do? Message-ID: <1991Jul2.130627.6619@software.org> List-Id: In article <1991Jul01.152134.16085@afit.af.mil> dlindsle@afit.af.mil (David T. Lindsley) writes: > > subtype Index is natural; -- range 0..100; > type Dyn_String (Size : Index := 0) is record > Data : string (1..Size); > end record; > > S: Dyn_String; > > But this still leaves me with a question. Why does this work with a > constrained subtype, but not with an unconstrained one? Either results > in the elaboration of a null array -- why is this a problem with an > unconstrained subtype? (Especially since NATURAL is a discrete (sub)type > anyway... This is a problem for many compilers for exactly the reasons already mentioned in previous followups. When a default value is supplied for the discriminant of the record, and then an *unconstrained* object is declared, the value of the discriminant for that object can be changed later. Therefore, the record is probably being allocated with enough space to contain an array of the maximum size allowed, despite that fact that its *initial* size is small. When the Index type is allowed to get as large as natural'last, this is a pretty large array. Two ways to fix this: 1) Constrain Index to a smaller range as you did, restricting the potential size of Dyn_String, so that less space gets allocated. 2) Declare S with a constraint: S : Dyn_String (100); but this is kind of pointless, because then S is required to *always* be exactly 100 chars long and is no longer a "dynamic" string. Some if this was explained better and in more detail in previous followups to the original question. I suggest that you go back and re-read them. --Fred -- Fred Stluka Internet: stluka@software.org Software Productivity Consortium UUNet: ...!uunet!software!stluka 2214 Rock Hill Rd, Herndon VA 22070 USA Voice: (703)742-7236