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,2ea02452876a15e1 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Choice of OO primitives in Ada95 Date: 1996/02/23 Message-ID: #1/1 X-Deja-AN: 140854397 references: <4gc2pu$6qj@ux1.lmu.edu> <312C236B.2344@informatik.uni-stuttgart.de> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-02-23T00:00:00+00:00 List-Id: In article <312C236B.2344@informatik.uni-stuttgart.de>, Bernd Holzmueller wrote: >Actually, the compiler _can_ work out if a tag is necessary. ... Are you saying that if I have a program that contains no dispatching at all (i.e. nothing is ever converted to a class-wide type), then it is possible for the compiler to avoid ever storing tags? I don't see how that can be true, because of re-dispatching. Consider: package P1 is type T1 is tagged null record; procedure P(X: T1); procedure Q(X: T1); end P1; with P1; use P1; package P2 is type T2 is new T1 with null record; -- Override Q, but not P: procedure Q(X: T2); end P2; with P1; use P1; with P2; use P2; procedure Client is Object: T2; begin P(T1(X)); -- This is *not* a dispatching call. end Client; I claim that the tag of Object (namely the tag representing type T2) must be made available to procedure P1.P. The tag could be stored as a hidden component of Object, or it could be passed as an extra parameter to P. Either way, there is some overhead in doing this. Now, suppose there's no dispatching anywhere in the program. For example, P might look like this: procedure P(X: T1) is begin Q(X); -- This is *not* a dispatching call. end P; Then we've wasted some time and space by making that tag available to P. Distributed overhead. So, what if we eliminate that tag? Well, then if P looks like this: procedure P(X: T1) is begin Q(T1'Class(X)); -- This *is* a dispatching call. end P; it won't work, because the above call is supposed to call the version of Q for T2. But the compiler cannot know, at compile time of Client, what the body of P looks like. Therefore, it *must* pass that information to P, just *in case* P does a dispatching call. QED. Unless, of course, you're willing to generate code at link time. - Bob