comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Ada 95 and Class attribute for none-tagged incomplete type
Date: Mon, 3 Aug 2009 08:26:24 -0700 (PDT)
Date: 2009-08-03T08:26:24-07:00	[thread overview]
Message-ID: <17b5de2e-74df-414a-b214-677344dc697e@x25g2000prf.googlegroups.com> (raw)
In-Reply-To: 8442c52d-805f-4ca8-95ab-b4c8e949d7cd@k6g2000yqn.googlegroups.com

On Aug 1, 11:55 pm, Hibou57 (Yannick Duchêne)
<yannick_duch...@yahoo.fr> wrote:
> Hello,
>
> I've learned something mostly surprising today : in Ada 95, this was
> allowed to use the Class attribute with a prefix which was an
> incomplete type.... even not tagged.
>
> I've learned about it here :
>
> http://www.adaic.org/standards/05rat/html/Rat-1-3-3.html>> ------------------
>
> The introduction of tagged incomplete types clarifies the ability to
> write
> type T_Ptr is access all T'Class;
> This was allowed in Ada 95 even though we had not declared T as tagged
> at this point. Of course it implied that T would be tagged. In Ada
> 2005 this is frowned upon since we should now declare that T is tagged
> incomplete if we wish to declare a class wide access type. For
> compatibility the old feature has been retained but banished to Annex
> J for obsolescent features.
>
> >> ------------------
>
> The part of the mentionned annex J>> ------------------
>
> For the first subtype S of a type T declared by an
> incomplete_type_declaration that is not tagged, the following
> attribute is defined:
> S'Class
> Denotes the first subtype of the incomplete class-wide type rooted at
> T. The completion of T shall declare a tagged type. Such an attribute
> reference shall occur in the same library unit as the
> incomplete_type_declaration.
>
> >> ------------------
>
> But why was it allowed ?
> There was no way to declare an incomplete tagged ?

Correct.  This just wasn't in the syntax.

> So why to allow reference to a Class attribute in such circumstances ?

You could do that if you knew that the type was going to be declared
as tagged when you got around to declaring the full type.

Keep in mind that this isn't a privacy issue.  The main reason for
incomplete types is so that you can declare linked lists and things
like that.  Allowing a 'Class reference to a type not yet declared as
tagged allowed things like this:

   type Rec;
   type Rec_Acc is access all Rec'Class;
   type Rec is tagged record
       ...
       Next : Rec_Acc;
   end record;

so that you could have a heterogeneous list of records.


> This seems weird ... to allow to make reference to a class attribute
> of a none-tagged type (even if the complete view is tagged)

It doesn't seem so weird to me; from a programmer's point of view, the
main purpose of incomplete types is so that you can define and refer
to the type's name ahead of time; therefore, there really isn't any
reason (for a programmer) to look at the type as an untagged type at
all.  It's a little different where private types are concerned,
because there are two views of the type---the partial view, which is
for packages that can't see inside the private part and thus can't see
the full declaration of the type; and the full view, for places that
*can* see the private part.  It's possible for the partial view to be
untagged and the full view to be tagged, so allowing 'Class in a place
where only the partial view is visible would be wrong.  But the "two
views" doesn't really apply to incomplete types.  (From the compiler's
standpoint, it does; but I'm talking from a programmer's standpoint
here.)

There is one exception to all of the above, and that's the case where
an incomplete type in the private part of a package is completed in
the package *body*.  Not having "tagged incomplete" types prevented
certain useful uses of the type, so the "is tagged;" syntax was
added.  I think that being able to use this in my Rec example above,
so that you can now declare an incomplete type as tagged before
applying 'Class, was more of a side benefit.  (AI95-326)


> Was this a design error or were there some reasons or is there
> something I did not understand ?

You could call it a small design error, but only a small one since the
cases where it made a difference were pretty obscure.

                                         -- Adam





  reply	other threads:[~2009-08-03 15:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-02  6:55 Ada 95 and Class attribute for none-tagged incomplete type Hibou57 (Yannick Duchêne)
2009-08-03 15:26 ` Adam Beneschan [this message]
2009-08-03 18:45   ` Dmitry A. Kazakov
2009-08-13  1:50   ` Randy Brukardt
2009-08-13  8:18     ` Niklas Holsti
2009-08-13 13:16       ` Robert A Duff
2009-08-14  4:21         ` Randy Brukardt
2009-08-14 19:01           ` Robert A Duff
2009-08-14 23:41             ` Randy Brukardt
2009-08-15 14:33               ` Robert A Duff
2009-08-14  4:17       ` 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