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: Bob Duff Newsgroups: comp.lang.ada Subject: Re: storage error: stack overflow Date: Wed, 19 Aug 2015 16:53:43 -0400 Organization: A noiseless patient Spider Message-ID: <87fv3ff19k.fsf@theworld.com> References: <87r3n0kc15.fsf@adaheads.sparre-andersen.dk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="e99bcc0f0b4289ef0350c938adfc1184"; logging-data="28523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/KCCfhYnUrQah12ehdpeRO" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:8L8lzpV/fh/IxaRaSxSWzsCKbuk= sha1:s+WkJC2PaDapgvTzPtDkbvA60z8= Xref: news.eternal-september.org comp.lang.ada:27511 Date: 2015-08-19T16:53:43-04:00 List-Id: hreba writes: > On 08/18/2015 11:16 AM, Jeffrey R. Carter wrote: >> On 08/18/2015 07:02 AM, hreba wrote: >>> >>> Huh? As much as I know you cannot declare variables of a type with unknown >>> storage requirements at compile time, such as class-wide types and arrays with >>> unknown range. >> >> These are "indefinite types". You can declare an object of an indefinite type as >> long as you supply an initialization expression: >> >> S : String := "Hello"; >> >> V : T'Class := Some_Function; >> > > If the object is initialized, the storage requirement is known at compile > type. No, as Jeff and Randy have pointed out, when you initialize an object with a call to a function that returns an indefinite subtype (such as String, or T'Class), the size of the object is determined at run time. What's more, it's determined by the function body -- it is not known in the callee until the function has returned. But that only works if you can initialize the object on its declaration. Sometimes, the declaration needs to occur at a certain place for visibility reasons, and only later is initialized. You need access types for that (possibly encapsulated in Holders, or whatever). It also doesn't work if the Tag needs to change. In the above, V'Tag is set to whatever Some_Function returns, and can never be changed. - Bob