From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,545a08a159900a97 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!x25g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada 95 and Class attribute for none-tagged incomplete type Date: Mon, 3 Aug 2009 08:26:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <17b5de2e-74df-414a-b214-677344dc697e@x25g2000prf.googlegroups.com> References: <8442c52d-805f-4ca8-95ab-b4c8e949d7cd@k6g2000yqn.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1249313184 32488 127.0.0.1 (3 Aug 2009 15:26:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Aug 2009 15:26:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x25g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7542 Date: 2009-08-03T08:26:24-07:00 List-Id: On Aug 1, 11:55=A0pm, Hibou57 (Yannick Duch=EAne) 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