comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: unconstrained records
Date: Sun, 22 Dec 2002 13:52:54 GMT
Date: 2002-12-22T13:52:54+00:00	[thread overview]
Message-ID: <WsjN9.424541$%m4.129058@rwcrnsc52.ops.asp.att.net> (raw)
In-Reply-To: 3e05aebf.3122500@news.freenet.de

Are you looking at an on-line version of the book?

Your answer is present in chapter 3 section 6 on-line.

  http://www.cs.kuleuven.ac.be/~dirk/ada-belgium/aia/ch_3_6a.html

The short answer is your sample code does not work.

From the date I'll assume this is not a homework question.

The longer answer:

Try replacing the line:

   type Test(Length : natural:= 0) is

With:

   subtype Test_Index is Natural range 0 .. 132;

   type Test(Length : Test_Index:= 0) is

When a default discriminent is provided, when you declare an instance
of the type without specifying the discriminant, memory will be reserved
for the largest value that may be assigned to the record.  The code you
posted raises a STORAGE_ERROR exception on Gnat 3.15p.

Steve
(The Duck)

"Jan" <see@messagebody.com> wrote in message
news:3e05aebf.3122500@news.freenet.de...
> Hi,
>
> I have found an interesting source code in the book "Ada in action",
> but the book could be better, because there is no background
> information. Here is the problem:
>
> procedure UnConstrained_Record is
>
>    type Test (length : natural := 0) is
>      record
>         text : string (1..length);
>      end record;
>
> name : Test;
>
> begin
>
>    name := (5, "Bimbo");
>
>    -- now I can resize the array inside the record
>
>    name := (14, "This is a test");
>
>    -- but now it comes
>
>    name := (3, "abc");
>
>    -- What happens to the memory? Are the 11 bytes freed
>    -- automatically?
>
> end UnConstrained_Record;
>
>
> Thanks!





  reply	other threads:[~2002-12-22 13:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-22 12:24 unconstrained records Jan
2002-12-22 13:52 ` SteveD [this message]
2002-12-22 18:54   ` Jan
2002-12-22 19:14     ` Robert A Duff
2002-12-27 20:34       ` Randy Brukardt
2002-12-23  4:30     ` SteveD
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox