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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a64004e5f547b1ed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-17 22:38:41 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!news-hog.berkeley.edu!ucberkeley!newshub.sdsu.edu!west.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!6d3a1e4a!not-for-mail From: "Eric G. Miller" Subject: Re: more to ada paper critic Newsgroups: comp.lang.ada Message-ID: References: <4519e058.0206170923.5b278bfe@posting.google.com> <3D0E2559.1080909@mail.com> <3D0E91AB.9080202@telepath.com> User-Agent: Pan/0.11.3 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: "Ted Dennison" Date: Tue, 18 Jun 2002 05:38:32 GMT NNTP-Posting-Host: 216.119.16.32 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1024378712 216.119.16.32 (Mon, 17 Jun 2002 22:38:32 PDT) NNTP-Posting-Date: Mon, 17 Jun 2002 22:38:32 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:26206 Date: 2002-06-18T05:38:32+00:00 List-Id: In <3D0E91AB.9080202@telepath.com>, Ted Dennison wrote: > Hyman Rosen wrote: >> Ted Dennison wrote: >> >>> This must be a C++ idiom with which I'm unfamiliar. I thought C++ >>> class declarations did not allow any part of the class's declaration >>> (like one of its fields) to be declared in a separate compilation. >> >> >> You're right. I think he's talking about the so-called "pimpl" technique, >> which isolates the implementation of a class into a file which is never >> seen by the user. The user only sees a class which has a set of methods, >> and one pointer to an implementation class. > > Ahh. So this *is* just like using a private pointer to a deferred record > type, except that we aren't as tempted to do it in Ada because we like > to avoid pointers where possible. In C: /* opaque.h */ #ifndef OPAQUE_H #define OPAQUE_H typedef struct opaque * Opaque; Opaque new_opaque (void); void destroy_opaque (Opaque *); /* other "public method" declarations */ #endif /* opaque_P.h */ #ifndef OPAQUE_P_H #define OPAQUE_P_H #include "opaque.h" struct opaque { /* stuff */ }; /* "private method" declarations */ #endif /* opaque.c */ #include #include "opaque_P.h" Opaque new_opaque (void) { Opaque this = malloc (sizeof *this); if (this != NULL) { /* initialize this */ } return this; } void destroy_opaque (Opaque *that) { if (that != NULL && *that != NULL) { free (*that); *that = NULL; } } ... Give the user access to "opaque.h" only, and the user can't easily peek into the structure contents, but must use the defined interface. Obviously, it still has safety problems, but this is C after all...