From: haven.umd.edu!uvaarpa!software.org!stluka@louie.udel.edu (Fred Stluka)
Subject: Re: What should this do?
Date: 2 Jul 91 13:06:27 GMT [thread overview]
Message-ID: <1991Jul2.130627.6619@software.org> (raw)
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
next reply other threads:[~1991-07-02 13:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-07-02 13:06 Fred Stluka [this message]
-- strict thread matches above, loose matches on Subject: below --
1991-07-02 17:09 What should this do? cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!petunia!nwebre
1991-07-01 15:21 voder!wlbr!lonex.radc.af.mil!blackbird.afit.af.mil!dlindsle
1991-07-01 12:45 CBW Consulting
1991-06-28 19:35 David T. Lindsley
1991-06-28 21:40 ` Howard Turner
1991-06-29 0:31 ` Jim Showalter
1991-06-29 16:44 ` Michael Feldman
1991-06-29 21:22 ` Jim Showalter
1991-06-29 5:52 ` rharwood
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox