From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Construction initialization problem
Date: Thu, 4 Dec 2008 16:17:56 -0600
Date: 2008-12-04T16:17:56-06:00 [thread overview]
Message-ID: <gh9l0i$gsj$1@munin.nbi.dk> (raw)
In-Reply-To: oscmgxrpod50$.g7h7snlssha0$.dlg@40tude.net
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:oscmgxrpod50$.g7h7snlssha0$.dlg@40tude.net...
> Consider this:
>
> type A is tagged limited null record;
> type B (X : not null access A'Class) is tagged limited null record;
>
> Now we want to specialize B so that its instances would already contain A:
You never explained why you would want the discriminant in the first place.
I would think that it would be better to do what you've said about C
(include the instance directly in it) from the beginning, and the problem
doesn't come up.
Access discriminants have a fairly high overhead in Ada (because of the
possibility of coextensions), so unless you *need* coextensions, they ought
to be avoided.
One could use a named access type instead to declare the discriminant if you
really need a discriminant. But the only time you must use a discriminant is
if you have a discriminant-dependent component, and there is no interesting
way to make a component dependent on an access discriminant. So I'd prefer
to just avoid the discriminant.
If you're using discriminants to stand in for a proper constructor, I say
"don't!!" Use a constructor function as the language intends (and force it
with a (<>) if you need it).
Randy.
> type C is new B with record
> Y : aliased A;
> end record;
>
> Now there seems no way to either create an object of C so that C.X would
> point to C.Y or else to derive from C a new type without discriminant:
>
> type D is new C (X => C.Y'Access) with null record; -- Illegal
> type D is new C (X => D.Y'Access) with null record; -- Illegal
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-12-04 22:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-04 16:08 Construction initialization problem Dmitry A. Kazakov
2008-12-04 17:35 ` Adam Beneschan
2008-12-04 22:17 ` Randy Brukardt [this message]
2008-12-04 23:02 ` Adam Beneschan
2008-12-06 1:47 ` Randy Brukardt
2008-12-05 9:00 ` Dmitry A. Kazakov
2008-12-06 1:42 ` Randy Brukardt
2008-12-06 10:16 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox