From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: Instantiating private types with discriminants?
Date: Thu, 11 May 2006 01:17:33 GMT
Date: 2006-05-11T01:17:33+00:00 [thread overview]
Message-ID: <Ngw8g.940264$x96.674589@attbi_s72> (raw)
In-Reply-To: <HeidnX-p77c9_f_ZRVny1Q@pipex.net>
Rick H wrote:
>
> But all this has a side-effect that I haven't considered: the fact
> that a variable declared as a class-wide type *requires* initialization
> means that the compiler can determine the variable's type statically.
> This means that the following will raise a constraint error:
> declare
> Var_A : General_T'Class := Get (10); -- Type_A
> begin
> Put (Var_A);
> Ada.Text_IO.New_Line;
> Var_A := Get (100.0); -- Type_B - constraint error!
> Put (Var_A);
> end;
Constraint_Error is raised at run time, so this isn't static. In the
most general case, a function returning the class-wide type may return
any of the types in the class based on external events, and so be
completely unknown statically (no matter how good a job of static
analysis the compiler does). So there must be cases when the actual type
of the variable is not known until run time. In practice, most compilers
are not going to bother, so this will always result in dispatching.
One thing about class-wide variables is that they are constrained to the
type of their initialization expression, and so can never be assigned
another type in the class (hence Constraint_Error). This is why it's
best to declare them as late as possible.
--
Jeff Carter
"My name is Jim, but most people call me ... Jim."
Blazing Saddles
39
next prev parent reply other threads:[~2006-05-11 1:17 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
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 [this message]
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