comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: generic formal object of class-wide type
Date: 1999/04/30
Date: 1999-04-30T00:00:00+00:00	[thread overview]
Message-ID: <wccd80mgokl.fsf@world.std.com> (raw)
In-Reply-To: m390bbs908.fsf@mheaney.ni.net

Matthew Heaney <matthew_heaney@acm.org> writes:

> "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:
...
> > The actual needs to be explicitly converted to the type of the
> > formal, like so:
> > 
> > package Q is new GQ (P.T'Class (P.C.O));
> 
> Yes, but why?
> 
> If I have a subprogram with a parameter of a class-wide type, like this:
> 
> procedure Op (O : T'Class);
> 
> and NT is a type in T'Class, then I can do this:
> 
> declare
>   O : NT;
> begin
>   Op (O);
> end;
> 
> 
> No conversion to type T'Class is required in order to call Op.
> 
> It is inconsistent that a type conversion is required in order pass the
> object as a generic actual.  I'd like to know the specific rule, and a
> rationale for the inconsistency.

There is some discussion of this in AARM-8.5.1(3.a-3.f).  Note that
generic formal 'in out' objects are not analogous to formal subprogram
parameters -- they are analogous to renaming declarations.  Compilers
take advantage of this -- they typically use the same code to analyze
generic instantiation with a generic formal 'in out', and to analyze an
object renaming declaration.  In fact, I noticed in an early version of
one Ada 95 compiler, that the compiler would complain about "illegal
renaming declaration" or some such, when there was no renaming in sight
-- just a generic instantiation.  The compiler was eventually fixed.

The Ada 83 language designers went to some trouble to make the rules
the same for both, and we tried to keep it that way for Ada 95.

See also AARM-12.4(1.a-1.b).

Note also that renaming declarations are kind of weird, in that certain
information in the declaration is ignored.  I don't like that, because
it causes confusion:

    X: constant Integer := -10;
    ...
    Y: Positive renames X;

Y is constant, even though it doesn't say so explicitly, and (worse) it
pretends to be Positive, but is actually negative.

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




  reply	other threads:[~1999-04-30  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-29  0:00 generic formal object of class-wide type Matthew Heaney
1999-04-29  0:00 ` Jean-Pierre Rosen
1999-04-29  0:00 ` David C. Hoos, Sr.
1999-04-29  0:00   ` Matthew Heaney
1999-04-30  0:00     ` Robert A Duff [this message]
1999-04-30  0:00       ` Richard D Riehle
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox