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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5d0ce0dbca0a2038 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Q: Primitive operation of a type Date: 1997/07/01 Message-ID: #1/1 X-Deja-AN: 254011376 References: <5oq51h$t7u@netline.jpl.nasa.gov> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-07-01T00:00:00+00:00 List-Id: In article <5oq51h$t7u@netline.jpl.nasa.gov>, vsnyder@math.jpl.nasa.gov (Van Snyder) wrote: >I've looked at Barnes's book, and Cohen's book, and I can't >decide whether it's possible for a procedure to be a primitive >operation of more than one type. It is, but an operation can only be primitive for one tagged type. For example, the operation Set_Col in package Ada.Text_IO is primitive for both type File_Type and type Positive_Count. But note that neither of these types are tagged. These issues are discussed in Mats Weber's PhD thesis. >If it's not possible, please send me a reference to the >relevant parts of the LRM. [snip] No, it is not possible for an operation to be primitive for more than one tagged type. >Which procedure is used when P is invoked with arguments of >types T11 and T21? Please refer me to sections of the LRM (or >Barnes's or Cohen's books) that explain the answer. Be careful though, to not interpret "can't be primitive for more than one type" to mean "can't have different tagged types as subprogram parameters." A operation can be primitive for one tagged type, but take additional class-wide parameters of another type. For example, package P is type T1 is tagged private; type T2 is tagged private; procedure Op1 (O1 : T1; O2 : T2); -- illegal procedure Op2 (O1 : T1; O2 : T2'Class); -- AOK procedure Op3 (O1 : T1'Class; O2 : T2); -- AOK2 procedure Op4 (O : T1'Class); procedure Op5 (O : T2'Class); procedure Op6 (O1 : T1'Class; O2 : T2'Class); procedure Op7 (O1 : T1; O2 : T1); -- OK ... end P; Op1 is illegal, because it takes more than one kind of tagged type as parameters. Op2 is a primitive operation of type T1, and it gets inherited by types that derive from T1. Op3 is a primitive opeation of type T2, and it gets inherited by types that derive from T2. Op2, because it takes an object of type T2'Class, is not a primitive operation of type T2. Op3, because it takes an object of type T1'Class, is not a primitive operation of type T3. Op4 is not a primitive operation of any type. Ditto for Op5 and Op6. Op7 is a primitive operation of type T1, and gets inherited by types that derive from T1. It's OK to have more than one parameter of a tagged type, it's just that they have to have the same tag. Op7 is interesting, because sometimes a run-time check will need to be made to ensure that both objects really have the same tag. For example, procedure P (O1, O2 : T1'Class) is begin Op7 (O1, O2); end; This will dispatch on the tag of the O1 and O2, but only if O1 and O2 have the same tag, which can't be determined until run-time. If the tag-check fails, then an exception is raised (I forget which, either Constraint_Error or Program_Error). One exception to this must-be-same-tag rule is in the case of the equality operator: procedure P (O1, O2 : T1'Class) is begin if O1 = O2 then This will dispatch on the equality operator, if the tags are the same. If the tags are different, then obviously the objects can't be the same, so no exception is raised (thankfully) and the function just returns False. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271