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-27 12:39:52 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!news-feed.riddles.org.uk!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: unconstrained records Date: Fri, 27 Dec 2002 14:34:27 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <3e05aebf.3122500@news.freenet.de> <3e0608b6.2790531@news.freenet.de> X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:32341 Date: 2002-12-27T14:34:27-06:00 List-Id: Robert A Duff wrote in message ... >see@messagebody.com (Jan) writes: > >> So when I write the following code (this one works), the string in >> "name" will ALWAYS occupy 15 bytes? >> >> subtype Max_Index is Natural range 0 .. 15; >> >> type Test (length : natural := 0) is >> record >> text : string (1..length); >> end record; >> >> name : Test; > >On most Ada compilers, that's true. There are (or were) *some* Ada >compilers that used implicit heap allocation to implement this sort of >thing, so that when you assign a different-sized value, the old one gets >deallocated and the new one allocated. Janus/Ada has always done this. I've always found the "standard" implementation suspicious, because it isn't what the programmer wrote. OTOH, it is better for embedded systems (because it is more deterministic), so that's why most of them use it. >It's quite difficult to get the heap-based implementation right. Consider renaming >Name.Text(3), for example. You're right that it is difficult, but renaming isn't a problem: it's illegal by 8.5.1(5). The primary problem is getting rid of the heap-allocated stuff when the object goes out of scope. For nested scopes, you don't want it to hang around. That problem was complicated by storage pools (you really want to use the correct pool for the allocation, but then you have to use the correct pool for deallocation, meaning you have to save it somewhere). Randy Brukardt.