home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / ada / 2377 < prev    next >
Encoding:
Text File  |  1992-08-17  |  2.4 KB  |  57 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Ada 9x Dispatching Question
  5. Message-ID: <9223120.6784@mulga.cs.mu.OZ.AU>
  6. Keywords: Ada Dispatching Polymorphism
  7. Sender: news@cs.mu.OZ.AU
  8. Organization: Computer Science, University of Melbourne, Australia
  9. References: <334@sps.com> <1992Aug17.215219.967@inmet.camb.inmet.com>
  10. Date: Tue, 18 Aug 1992 10:54:39 GMT
  11. Lines: 44
  12.  
  13. bwhite@cobra.camb.inmet.com (Bill White) writes:
  14.  
  15. >The MRT has discussed this at length in the past.  Tucker believes that
  16. >it is important to have a syntactic marker to tell when a call is
  17. >dispatching.  An alternative rule would be the C++ rule, where all
  18. >dispatching operations dispatch always.  (Ada9X dispatching operations
  19. >are roughly equivalent to C++ virtual operations.)  This means that the 
  20. >compiler could not replace a dispatching call with a non-dispatching
  21. >call even if the compiler knows where the routine is going to go
  22. >anyway.  This is considered expensive.
  23.  
  24. I don't understand why the compiler can't replace a dispatching call
  25. with a non-dispatching one if it really does know the exact type of
  26. the operand.  This is quite possible in C++. Indeed, in C++ you can
  27. declare a function to be both inline and virtual, so that if the
  28. compiler manages to avoid the dispatch, it can then insert the code
  29. directly and avoid any function call altogether.
  30.  
  31. For example, suppose BigCircle is derived from Circle.
  32.  
  33.     Circle c;    // An actual circle
  34.     BigCircle b;    // BigCircle is-a circle
  35.         
  36.     Circle &c1 = c;    // A reference to a genuine circle 
  37.     Circle &c2 = b; // A reference to a circle of some sort
  38.  
  39.     c2.draw();    // dispatches (needs to, since c2 actually refers
  40.             // to a BigCircle not a Circle).
  41.  
  42.     c.draw();    // need not dispatch, since compiler knows the exact
  43.             // type of c.
  44.  
  45.     c1.draw();    // will probably dispatch, since c1 is only a reference
  46.             // to a Circle, not actually a Circle.
  47.             // A clever compiler could deduce from the
  48.             // initialization for c1 that it actually refers to a
  49.             // genuine Circle and avoid dispatching, but current
  50.             // compilers aren't that smart I suspect.
  51.  
  52. -- 
  53. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  54. This .signature VIRUS is a self-referential statement that is true - but 
  55. you will only be able to consistently believe it if you copy it to your own
  56. .signature file!
  57.