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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3d9acd0750841603 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: How to hide type internals Date: Fri, 30 Jun 2006 13:26:11 +0200 Message-ID: <4gkfv6F1nnvl6U1@individual.net> References: <1151664636.528401.15590@d56g2000cwd.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net puFCpHlgKZQZ0uJzSM3TFwI6LHB+rWzOhlRvwd0OZSlCOHb68= User-Agent: KNode/0.10.2 Xref: g2news2.google.com comp.lang.ada:5331 Date: 2006-06-30T13:26:11+02:00 List-Id: Gerd wrote: > Hi, > > I would like to write a package that exports functions using a special > type, without showing the details in the spec (even not in the private > part). > In Modula-2 one can declare opaque types (which mostly are pointers but > also can be any type of word size). I've done this in occasions where I want to have a multi-platform package, so switching bodies is enough, keeping the same spec file. Like this: package Blah is type External is private; -- Operations on external private type Internal; -- forward declaration type Internal_Acess is access all Internal; type External is record Ptr : Internal_Access; end record; end; And then you define Internal in the body. With Ada05 you can even get rid of Internal_Access and simply have type External is record Ptr : access Internal; end record; Of course you can have reference counting, deep copying or whatever making External a Controlled type, so you can have a proper abstraction (This will be probably a requisite for initialization anyways...) Hope this helps.