Re: "data hiding" prototype code
- From: "Jonas" <spamhereplease@xxxxxxxxx>
- Date: Wed, 11 Apr 2007 23:39:34 GMT
"sofeng" <sofengboe@xxxxxxxxx> wrote in message
news:1176328415.501183.20910@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thank you for your reply. See my comments below.
On Apr 11, 1:18 pm, "bluejack" <bluuj...@xxxxxxxxx> wrote:
First of all, making the variables static at file scope doesn't really
achieve the goal of encapsulation, particularly when you publish the
struct definition in the header. Secondly, static variables at file
scope are not much better than globals: they're certainly not thread
safe, and you open yourself to other sorts of errors as well.
I'm not sure what you mean by "publish the struct definition in the
header". I only put the typedef in the header-- that doesn't publish
the struct definition, right?
In your header file, you have
typedef struct {
double data1;
double data2;
double data3;
} ALGORITHM_DATA;
Instead, separate the typedef and the struct definition into header and
implementation files:
/* foo.h */
typedef struct foo_st foo_t;
/* foo.c */
#include "foo.h"
struct foo_st {
int bar;
};
Now, struct foo_st will be undefined outside of foo.c, which is what you
want to achieve. Pointers to foo_t can be defined by users of foo, but foo_t
objects cannot, leaving your code in charge of this and anything that has to
do with foo_t internals.
--
Jonas
.
- Follow-Ups:
- Re: "data hiding" prototype code
- From: sofeng
- Re: "data hiding" prototype code
- References:
- "data hiding" prototype code
- From: sofeng
- Re: "data hiding" prototype code
- From: bluejack
- Re: "data hiding" prototype code
- From: sofeng
- "data hiding" prototype code
- Prev by Date: Re: char pointers?
- Next by Date: Re: Segmentation Fault....
- Previous by thread: Re: "data hiding" prototype code
- Next by thread: Re: "data hiding" prototype code
- Index(es):
Relevant Pages
|