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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: storage error: stack overflow Date: Tue, 18 Aug 2015 22:10:07 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <87r3n0kc15.fsf@adaheads.sparre-andersen.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 19 Aug 2015 05:08:27 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ee44d3db9c41f5ad88d7e8e8f0268f05"; logging-data="14350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KR08o+uzWXyyvhnoSNWDH4diKucxgL64=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: X-Mozilla-News-Host: news://freenews.netfront.net Cancel-Lock: sha1:39hAoRe/i2HHsCOICPQ/DnXGxnU= Xref: news.eternal-september.org comp.lang.ada:27501 Date: 2015-08-18T22:10:07-07:00 List-Id: On 08/18/2015 06:48 PM, hreba wrote: > >> V : T'Class := Some_Function; > > If the object is initialized, the storage requirement is known at compile type. > My situation is a typical object orientation case as shown in a lot of examples > where you have a (possibly abstract) base type and several extensions and where > the dynamic type of a variable is not known at compile time. Classic example > would be an inhomogeneous list (I know in practice you use a container for that, > it is just an example). > My knowledge of Ada exceeds Ada 95 only by very little but I am pretty sure that > in such a case one uses variables of a class-wide type, and as one cannot > initialize them one has to declare them as access types. > > Or, if I am wrong, what would be the best practice for that? If an object is initialized by a function call, as above, the size is not known at compile time. Consider S : String := Ada.Text_IO.Get_Line; The size of S is not known until run time. Thus it is often possible to use a normal object declaration for a value of an indefinite type not known until run time. Block statements are useful for delaying a declaration until then. As Randy pointed out, an indefinite holder can be used as a variable of a class-wide type. Holders were introduced in Ada 12, but it's easy enough to write one if you're using an earlier compiler. Your application code does not use access types in either case. You'll need to use an access type to implement an indefinite holder, but such use will be in a single place and so easier to get correct than with access values scattered throughout your application -- Jeff Carter "Blessed are they who convert their neighbors' oxen, for they shall inhibit their girth." Monty Python's Life of Brian 83