From: "Ludovic Brenta" <ludovic@ludovic-brenta.org>
Subject: Re: Instantiating private types with discriminants?
Date: 9 May 2006 06:56:53 -0700
Date: 2006-05-09T06:56:53-07:00 [thread overview]
Message-ID: <1147183013.687672.246320@g10g2000cwb.googlegroups.com> (raw)
In-Reply-To: <QD08g.28768$Nb2.521930@news1.nokia.com>
rick H a écrit :
> Hello,
>
> I'm slowly learning Ada for my own amusement, and I've ground to a halt
> trying to understand something. If some kind sole could explain it to
> me, I'd be very grateful.
>
> I've defined two types, each with a descriminant, and each with its own
> access type. One of the type's implementations is, however, private:
>
> package Discrim is
> type Type_A (Param : Integer := 100) is null record;
> type Type_A_Ptr is access Type_A;
>
> -- same as above, but implementation now private...
> type Type_B (Param : Integer := 100) is private;
> type Type_B_Ptr is access Type_B;
> private
> type Type_B (Param : Integer := 100) is null record;
> end Discrim;
>
>
> When I use "new" on two variables declared as Type_A_Ptr and Type_B_Ptr,
> one requires a type conversion for the discriminant, whereas the other
> requires a qualified expression:
>
> with Discrim; use Discrim;
> procedure Use_Discrim is
> A : Type_A_Ptr; -- public implementation
> B : Type_B_Ptr; -- private implementation
> begin
> A := new Type_A'(Param => 100); -- qualified expression
> B := new Type_B (Param => 123); -- type conversion
> end Use_Discrim;
>
> So, my question to the experts is: Why does "privatising" a type's
> details change the way that you "new" instantiations of it?
Actually, the declaration of B is not a type conversion; it is an
allocator that uses a subtype_mark, as opposed to a
qualified_expression (see ARM 4.8(2)).
Use_Discrim sees all the components of Type_A (there is only one: the
discriminant), and so the qualified_expression is legal. But you could
also use an allocator with a subtype_mark, so it is incorrect to say
that A *requires* a qualified_expression; it only *allows* one:
A := new Type_A (Param => 100); -- legal
In contrast, Use_Discrim does not see the components of Type_B other
than the discriminant, so doesn't know if there are any, and so the
qualified_expression'aggregate (defined in 4.7(2)) would be illegal,
since aggregates must contain one expression for each component, per
4.3.1(9).
--
Ludovic Brenta.
next prev parent reply other threads:[~2006-05-09 13:56 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-09 13:17 Instantiating private types with discriminants? rick H
2006-05-09 13:45 ` Georg Bauhaus
2006-05-09 14:06 ` rick H
2006-05-09 13:56 ` Ludovic Brenta [this message]
2006-05-09 14:24 ` rick H
2006-05-09 19:48 ` Ludovic Brenta
2006-05-09 14:05 ` Dmitry A. Kazakov
2006-05-09 14:48 ` rick H
2006-05-09 15:20 ` Jerry Petrey
2006-05-09 15:42 ` rick H
2006-05-09 15:53 ` Avoiding use Ada.Tags (was Re: Instantiating private types with discriminants?) Alex R. Mosteo
2006-05-09 16:01 ` Instantiating private types with discriminants? Dmitry A. Kazakov
2006-05-10 7:42 ` rick H
2006-05-10 9:09 ` Ludovic Brenta
2006-05-10 11:49 ` Georg Bauhaus
2006-05-10 13:44 ` rick H
2006-05-10 14:21 ` Ludovic Brenta
2006-05-10 15:10 ` rick H
2006-05-10 15:45 ` Ludovic Brenta
2006-05-10 14:41 ` Dmitry A. Kazakov
2006-05-10 15:34 ` rick H
2006-05-10 19:01 ` Georg Bauhaus
2006-05-10 19:05 ` Ludovic Brenta
2006-05-10 21:52 ` Rick H
2006-05-11 1:17 ` Jeffrey R. Carter
2006-05-11 7:44 ` Dmitry A. Kazakov
2006-05-11 8:27 ` rick H
2006-05-11 10:28 ` Dmitry A. Kazakov
2006-05-11 15:59 ` Robert A Duff
2006-05-12 7:37 ` Dmitry A. Kazakov
2006-05-12 9:24 ` Georg Bauhaus
2006-05-12 12:40 ` Dmitry A. Kazakov
2006-05-12 18:25 ` Randy Brukardt
2006-05-09 19:57 ` "Use" and "=" for Tags (was: Re: Instantiating private types with discriminants?) Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox