Re: Question about a struct declaration
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Wed, 16 Apr 2008 18:41:41 +0000
Andrey Tarasevich said:
Richard Heathfield wrote:
...
Er... I disagree.
Well, then, can you come up with a different implementation hiding
technique that would satisfy the following two requirements:
1) Client code can define objects of type 'T'
2) Client code doesn't see the implementation details of the concept
type 'T' represents
?
Yes, by carefully interpreting your words in a way convenient to myself. I
choose to interpret 'define' as meaning 'create via a function' (which is
completely at odds with our usual meaning of 'define', as you don't have
to remind me), and I choose not to count structness as an implementation
detail. Given those weasel words, I can do it:
Interface:
struct T_;
typedef struct T_ T;
T *t_create(whatever);
void t_destroy(T **);
int t_use(T *, whatever);
etc
Implementation: hidden :-)
Hide the pointeriness? No, it actually _doesn't_ hide the pointeriness.
The pointeriness will be clearly visible in the interface header, in the
typedef.
Right, so you gain nothing in terms of information hiding, but lose the
convenience to the user-programmer of being reminded through usage that
he's dealing with a here-be-dragons pointer.
a pointerYeah, well, I've only got one pair of 'ands, ain't I?
hidden in a typedef is a standard, widely used and accepted idiom.
I don't know what to say...
Translation: it's going to take me a long time to persuade everyone /not/
to accept that idiom, working alone. (Especially as I'm not actually all
that fussed about it, certainly not enough to commit my declining years to
a one-man anti-hiding-pointers-in-typedefs crusade.)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
- Follow-Ups:
- Re: Question about a struct declaration
- From: Andrey Tarasevich
- Re: Question about a struct declaration
- References:
- Question about a struct declaration
- From: heavyz
- Re: Question about a struct declaration
- From: Andrey Tarasevich
- Re: Question about a struct declaration
- From: Richard Heathfield
- Re: Question about a struct declaration
- From: Andrey Tarasevich
- Re: Question about a struct declaration
- From: Richard Heathfield
- Re: Question about a struct declaration
- From: Andrey Tarasevich
- Question about a struct declaration
- Prev by Date: Re: why this does n't works
- Next by Date: Re: How to eliminate this global variable, silent?
- Previous by thread: Re: Question about a struct declaration
- Next by thread: Re: Question about a struct declaration
- Index(es):
Relevant Pages
|