From: Georg Bauhaus <bauhaus@futureapps.invalid>
Subject: Re: storage error: stack overflow
Date: Wed, 19 Aug 2015 10:44:58 +0200
Date: 2015-08-19T10:44:58+02:00 [thread overview]
Message-ID: <mr1fj5$nt6$1@dont-email.me> (raw)
In-Reply-To: <d3i5k1Fh07U1@mid.individual.net>
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.
next prev parent reply other threads:[~2015-08-19 8:44 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-11 21:53 storage error: stack overflow hreba
2015-08-11 22:19 ` Jeffrey R. Carter
2015-08-12 15:01 ` hreba
2015-08-12 16:00 ` AdaMagica
2015-08-12 17:51 ` Jeffrey R. Carter
2015-08-13 2:17 ` hreba
2015-08-12 8:27 ` briot.emmanuel
2015-08-13 1:34 ` hreba
2015-08-13 2:53 ` Jeffrey R. Carter
2015-08-13 7:05 ` Simon Wright
2015-08-14 13:53 ` hreba
2015-08-14 16:01 ` Simon Wright
2015-08-14 17:00 ` Simon Wright
2015-08-13 7:19 ` Simon Wright
2015-08-14 13:20 ` hreba
2015-08-12 10:31 ` Markus Schöpflin
2015-08-13 1:36 ` hreba
2015-08-12 10:57 ` Simon Wright
2015-08-13 0:55 ` hreba
2015-08-13 6:58 ` Simon Wright
2015-08-18 2:16 ` hreba
2015-08-18 5:49 ` Jeffrey R. Carter
2015-08-18 7:24 ` Egil H H
2015-08-18 12:23 ` hreba
2015-08-18 12:37 ` Jacob Sparre Andersen
2015-08-18 14:02 ` hreba
2015-08-18 14:11 ` Dmitry A. Kazakov
2015-08-18 14:16 ` Jeffrey R. Carter
2015-08-18 20:56 ` Randy Brukardt
2015-08-19 1:48 ` hreba
2015-08-19 5:10 ` Jeffrey R. Carter
2015-08-19 8:44 ` Georg Bauhaus [this message]
2015-08-19 11:56 ` hreba
2015-08-19 20:53 ` Bob Duff
2015-08-18 14:15 ` Egil H H
2015-08-19 13:07 ` hreba
2015-08-18 14:16 ` Jeffrey R. Carter
2015-08-19 13:12 ` hreba
2015-08-19 20:47 ` Bob Duff
2015-08-19 21:47 ` Jeffrey R. Carter
2015-08-20 7:18 ` Dmitry A. Kazakov
2015-08-20 20:48 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox