home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Ada 9x Dispatching Question
- Message-ID: <9223120.6784@mulga.cs.mu.OZ.AU>
- Keywords: Ada Dispatching Polymorphism
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <334@sps.com> <1992Aug17.215219.967@inmet.camb.inmet.com>
- Date: Tue, 18 Aug 1992 10:54:39 GMT
- Lines: 44
-
- bwhite@cobra.camb.inmet.com (Bill White) writes:
-
- >The MRT has discussed this at length in the past. Tucker believes that
- >it is important to have a syntactic marker to tell when a call is
- >dispatching. An alternative rule would be the C++ rule, where all
- >dispatching operations dispatch always. (Ada9X dispatching operations
- >are roughly equivalent to C++ virtual operations.) This means that the
- >compiler could not replace a dispatching call with a non-dispatching
- >call even if the compiler knows where the routine is going to go
- >anyway. This is considered expensive.
-
- I don't understand why the compiler can't replace a dispatching call
- with a non-dispatching one if it really does know the exact type of
- the operand. This is quite possible in C++. Indeed, in C++ you can
- declare a function to be both inline and virtual, so that if the
- compiler manages to avoid the dispatch, it can then insert the code
- directly and avoid any function call altogether.
-
- For example, suppose BigCircle is derived from Circle.
-
- Circle c; // An actual circle
- BigCircle b; // BigCircle is-a circle
-
- Circle &c1 = c; // A reference to a genuine circle
- Circle &c2 = b; // A reference to a circle of some sort
-
- c2.draw(); // dispatches (needs to, since c2 actually refers
- // to a BigCircle not a Circle).
-
- c.draw(); // need not dispatch, since compiler knows the exact
- // type of c.
-
- c1.draw(); // will probably dispatch, since c1 is only a reference
- // to a Circle, not actually a Circle.
- // A clever compiler could deduce from the
- // initialization for c1 that it actually refers to a
- // genuine Circle and avoid dispatching, but current
- // compilers aren't that smart I suspect.
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature VIRUS is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-