home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.eng.gtefsd.com!paladin.american.edu!howland.reston.ans.net!spool.mu.edu!olivea!sgigate!sgi!wdl1!wdl39!mab
- From: mab@wdl39.wdl.loral.com (Mark A Biggar)
- Newsgroups: comp.lang.ada
- Subject: Re: private types and recompilation
- Message-ID: <1993Jan28.180853.2008@wdl.loral.com>
- Date: 28 Jan 93 18:08:53 GMT
- References: <7277@grus.cs.nps.navy.mil> <9301271722.aa25516@Paris.ics.uci.edu>
- Sender: news@wdl.loral.com
- Organization: Loral Western Development Labs
- Lines: 64
-
- In article <9301271722.aa25516@Paris.ics.uci.edu> kanderso@mabillon.ICS.UCI.EDU (Kenneth Anderson) writes:
- >In comp.lang.ada you write:
- >>When Ada 83 was designed, why did the designers choose to put
- >>the details of private types in package specifications, rather than
- >>in package bodies (which is more in the spirit of information hiding, and
- >>better supports independent compilation).
- >I'm not sure, but I think because the compiler needs to know the size
- >of the types so that it can allocate space for parameters in the
- >subprograms that are defined in the spec.
- >>generic
- >> type ATOM is private;
- >>package LIST_ADT is
- >> type POSITION is private;
- >> type LIST is private;
- >> procedure CREATE(L: in out LIST);
- >> procedure INSERT_AFTER(L: in out LIST; P: POSITION; A: ATOM);
- >> ...
- >>private
- >> type LIST;
- >> type POSITION is access LIST;
- >You only need the previous two lines. The declaration below can be
- >hidden in the body of the package.
- >> type LIST is record
- >> A: ATOM;
- >> NEXT: POSITION;
- >> end record;
- >>end LIST_ADT;
-
- Sorry but you can't do that because LIST is mentioned in the non-private
- part of the package spec, its completing declaration must be included in the
- private part. It is only incomplete types that are first introduced in the
- private part that can be completed in the package body. So if you wrote
- the package like the following then you can push the completed type to the
- body. Besides the above package definition is clumsy anyway because the
- abstraction for a linked list does not need both the node type and the access
- to the node be externally visible.
-
- generic
- type ATOM is private;
- package LIST_ADT is
- type LIST is private;
- procedure CREATE(L: in out LIST);
- procedure INSERT(L: in out LIST, A: ATOM);
- ...
- private
- type NODE;
- type LIST is access NODE;
- end LIST_ADT;
-
- package body LIST_ADT is
- ...
- type NODE is record
- A: ATOM;
- NEXT: LIST;
- end record;
- ...
- end LIST_ADT;
-
- Notice that the incomplete type NODE is only mentioned in the private part
- of the spec so its completing declaration can wait until the package body.
-
- --
- Mark Biggar
- mab@wdl1.wdl.lroal.com
-