comp.lang.ada
 help / color / mirror / Atom feed
From: "Eric G. Miller" <egm2@jps-nospam.net>
Subject: Re: more to ada paper critic
Date: Tue, 18 Jun 2002 05:38:32 GMT
Date: 2002-06-18T05:38:32+00:00	[thread overview]
Message-ID: <pan.2002.06.18.05.40.30.378847.14666@jps-nospam.net> (raw)
In-Reply-To: 3D0E91AB.9080202@telepath.com

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 <stdlib.h>
#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...



  reply	other threads:[~2002-06-18  5:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-17 10:28 more to ada paper critic Immanuel Scholz
2002-06-17 17:23 ` Ted Dennison
2002-06-17 18:07   ` Hyman Rosen
2002-06-18  1:50     ` Ted Dennison
2002-06-18  5:38       ` Eric G. Miller [this message]
2002-06-18 13:42     ` Immanuel Scholz
  -- strict thread matches above, loose matches on Subject: below --
2002-06-17 11:33 Grein, Christoph
2002-06-17 15:16 Gautier direct_replies_not_read
2002-06-17 15:26 Gautier direct_replies_not_read
2002-06-18 13:30 ` Immanuel Scholz
2002-06-18 13:35   ` Steve O'Neill
2002-06-18 17:59   ` Christoph Schlegel
2002-06-19 20:41     ` Immanuel Scholz
2002-06-20 19:39       ` Christoph Schlegel
2002-06-19 16:05   ` Britt Snodgrass
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox