home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / ada / 4107 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  2.6 KB

  1. Path: sparky!uunet!europa.eng.gtefsd.com!paladin.american.edu!howland.reston.ans.net!spool.mu.edu!olivea!sgigate!sgi!wdl1!wdl39!mab
  2. From: mab@wdl39.wdl.loral.com (Mark A Biggar)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: private types and recompilation
  5. Message-ID: <1993Jan28.180853.2008@wdl.loral.com>
  6. Date: 28 Jan 93 18:08:53 GMT
  7. References: <7277@grus.cs.nps.navy.mil> <9301271722.aa25516@Paris.ics.uci.edu>
  8. Sender: news@wdl.loral.com
  9. Organization: Loral Western Development Labs
  10. Lines: 64
  11.  
  12. In article <9301271722.aa25516@Paris.ics.uci.edu> kanderso@mabillon.ICS.UCI.EDU (Kenneth Anderson) writes:
  13. >In comp.lang.ada you write:
  14. >>When Ada 83 was designed, why did the designers choose to put
  15. >>the details of private types in package specifications, rather than
  16. >>in package bodies (which is more in the spirit of information hiding, and
  17. >>better supports independent compilation).
  18. >I'm not sure, but I think because the compiler needs to know the size
  19. >of the types so that it can allocate space for parameters in the
  20. >subprograms that are defined in the spec.
  21. >>generic
  22. >>  type ATOM is private;
  23. >>package LIST_ADT is
  24. >>  type POSITION is private;
  25. >>  type LIST is private;
  26. >>  procedure CREATE(L: in out LIST);
  27. >>  procedure INSERT_AFTER(L: in out LIST; P: POSITION; A: ATOM);
  28. >>  ...
  29. >>private
  30. >>  type LIST;
  31. >>  type POSITION is access LIST;
  32. >You only need the previous two lines.  The declaration below can be
  33. >hidden in the body of the package.
  34. >>  type LIST is record
  35. >>    A: ATOM;
  36. >>    NEXT: POSITION;
  37. >>  end record;
  38. >>end LIST_ADT;
  39.  
  40. Sorry but you can't do that because LIST is mentioned in the non-private
  41. part of the package spec, its completing declaration must be included in the
  42. private part.  It is only incomplete types that are first introduced in the 
  43. private part that can be completed in the package body.  So if you wrote
  44. the package like the following then you can push the completed type to the
  45. body.  Besides the above package definition is clumsy anyway because the
  46. abstraction for a linked list does not need both the node type and the access
  47. to the node be externally visible.
  48.  
  49. generic
  50.     type ATOM is private;
  51. package LIST_ADT is
  52.     type LIST is private;
  53.     procedure CREATE(L: in out LIST);
  54.     procedure INSERT(L: in out LIST, A: ATOM);
  55.     ...
  56. private
  57.     type NODE;
  58.     type LIST is access NODE;
  59. end LIST_ADT;
  60.  
  61. package body LIST_ADT is
  62.     ...
  63.     type NODE is record
  64.     A: ATOM;
  65.     NEXT: LIST;
  66.     end record;
  67.     ...
  68. end LIST_ADT;
  69.  
  70. Notice that the incomplete type NODE is only mentioned in the private part
  71. of the spec so its completing declaration can wait until the package body.
  72.  
  73. --
  74. Mark Biggar
  75. mab@wdl1.wdl.lroal.com
  76.