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=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fc203759328316c2 X-Google-Attributes: gid103376,public From: dhunter@interserf.net (David Hunter) Subject: Re: Question about tagged types and functions Date: 1996/05/22 Message-ID: <4nvhdo$ri7@ns.interserf.net>#1/1 X-Deja-AN: 156138165 references: <4ntg05$qgc@ns.interserf.net> <4xpw7xpoc6.fsf@leibniz.enst-bretagne.fr> content-type: Text/Plain; charset=US-ASCII organization: Internet Services Of Fredericksburg mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-05-22T00:00:00+00:00 List-Id: In article <4xpw7xpoc6.fsf@leibniz.enst-bretagne.fr>, Laurent.Guerby@enst-bretagne.fr says... > >David> Why does Ada-95 (GNAT 3.01a) tell me that I also *must* have: > >David> function Create return DerivedType; > >David> There is something going on with tagged types and functions >David> that I don't understand because if I use > >David> procedure Create(a : out BaseType); > >David> it (Ada-95) does not object. > > The status of functions (primitives) that dispatch on result is >special in Ada 95. See RM95-3.9.3(4-6). Or better, read the paper "Ada >9X Tagged Types and their Implementation in GNAT" by Cyrille Comar and >Brett Porter Thank you for your timely response. I read this paper and there is indeed a paragraph that explictly addresses my question. They explain that the overloading of Create is necessary because: "otherwise the inherited function would return an object of the parent type, that is to say an incomplete object." Obviously I can see that you want to avoid any situation in which you end up with "derived_object := parent_object" but doesn't Ada-95 forbid that anyway? I mean, you couldn't do d : DerivedType; b : BaseType; d := b; so the error "d := Create;" would be caught by the type rules anyway, right? I guess I'm back to my original question. Maybe it would help if someone could provide an example in which the problem described by the paper occurs (one that would not be otherwise detected). ============================== David Hunter (hunter@mwc.edu) CPSC Dept. Mary Washington College Fredericksburg, VA 22401