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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: storage error: stack overflow Date: Wed, 19 Aug 2015 10:44:58 +0200 Organization: A noiseless patient Spider Message-ID: References: <87r3n0kc15.fsf@adaheads.sparre-andersen.dk> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 19 Aug 2015 08:43:17 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="a6ee0cade24da99d9bc38b7faa265682"; logging-data="24486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CmhOwxKYAN23RUdD4HaOSLPNTgUC+T/Q=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 In-Reply-To: Cancel-Lock: sha1:4ch8UCCcwhea84ESpY0p/gj236g= Xref: news.eternal-september.org comp.lang.ada:27502 Date: 2015-08-19T10:44:58+02:00 List-Id: On 19.08.15 03:48, hreba wrote: > 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. The assumption that limited objects cannot be initialized like non-limited (by sort of copying a value) is no longer true, and it wasn't the whole truth in Ada 95. There are cases when nothing but an access type will do. But due to build-in-place, limited tagged objects can be declared and initialized, by aggregate or by function call, using just traditional syntax as Jeffrey Carter explains. This includes objects of a class-wide type, Built-in-place (in situ), perhaps simplifying, means that the limited object is declared and passed/used behind the scenes, for initialization. For example, the object that is declared becomes the to-be-returned object if there is a function call after “:=” in the declaration. (See "extended return" of Ada 2005.) Given package Classwide is type T0 is abstract tagged limited null record; type T1 is new T0 with private; function Make return T1; function Produce (Variant : Boolean) return T1'Class; private type T1 is new T0 with record -- note default values for "default construction" Name : Character := '?'; end record; end Classwide; package body Classwide is type T2 is new T1 with record Count : Natural; end record; function Make return T2; function Make return T1 is begin return T1'(T0 with Name => '*'); end Make; function Make return T2 is begin return T2'(T1'(Make) with Count => 0); end Make; function Produce (Variant : Boolean) return T1'Class is begin case Variant is when False => return T1'(T0 with Name => 'T'); when True => return T2'(T0 with Name => 'F', Count => 0); end case; end Produce; end Classwide; Then, the type hierarchy above includes limited T0, T1, and invisible T2. All of these types can be used to declare or create objects of specific types and of class-wide types. with Classwide; procedure Main is use Classwide; X : T1; C : T1'Class := Make; CC : T1'Class := Produce (Variant => False); procedure Takes_T1C (Object : in T1'Class) is separate; procedure Mods_T1C (Object : in out T1'Class) is separate; begin Takes_T1C (X); Takes_T1C (C); Takes_T1C (CC); Takes_T1C (Make); Takes_T1C (Produce (Variant => True)); Mods_T1C (X); Mods_T1C (C); Mods_T1C (CC); end Main; The Ada Rationale will illustrate and explain.