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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ea0955083361ce29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-22 05:52:54 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn11feed!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail From: "SteveD" Newsgroups: comp.lang.ada References: <3e05aebf.3122500@news.freenet.de> Subject: Re: unconstrained records X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc52.ops.asp.att.net 1040565174 12.211.13.75 (Sun, 22 Dec 2002 13:52:54 GMT) NNTP-Posting-Date: Sun, 22 Dec 2002 13:52:54 GMT Organization: AT&T Broadband Date: Sun, 22 Dec 2002 13:52:54 GMT Xref: archiver1.google.com comp.lang.ada:32194 Date: 2002-12-22T13:52:54+00:00 List-Id: 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" 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!