opaque style question
From: Capstar (spam0_at_deleg.homeip.net)
Date: 04/15/04
- Next message: Ioannis Vranos: "Re: Is it standard and practical to use long long types?"
- Previous message: Joona I Palaste: "Re: [OT] Re: malloc + 4??"
- Next in thread: Jarno A Wuolijoki: "Re: opaque style question"
- Reply: Jarno A Wuolijoki: "Re: opaque style question"
- Reply: E. Robert Tisdale: "Re: opaque style question"
- Maybe reply: CBFalconer: "Re: opaque style question"
- Reply: Keith Thompson: "Re: opaque style question"
- Reply: Capstar: "Re: opaque style question"
- Maybe reply: Joe Wright: "Re: opaque style question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 15 Apr 2004 15:26:01 +0200
Hi NG,
I've read some time ago in this NG, that when you're writing a library
it can be good practice to use an opaque type to point to your
structures if the user doesn't need to modify the structure himself.
This way the internal structure of the lib can be changed, and the lib
can be recompiled, but the application using the lib doesn't need to be
recompiled.
But then there are two ways to define the opque type:
#typedef struct libstruct lib_t;
or
#typedef struct libstruct * lib_t;
I'm not sure which one to use. I also read somewhere that it's bad
practice to make a typedef to a pointer in such a way that it is not
obvious from looking at the type, in this case lib_t, that it is a
pointer to whatever. So that would mean it would be best to use the
first typedef.
But if I use the first way, In the application I need to declare
lib_t *my_opaque_variable;
If I don't do it that way, I will get a compiler error because it
doesn't know the size of lib_t.
So that would mean the second typedef would be better, because the
compiler will always know the sizeof of a pointer.
So what is the usual way to do this?
Thanks in advance,
Mark
-- <<Remove the del for email>>
- Next message: Ioannis Vranos: "Re: Is it standard and practical to use long long types?"
- Previous message: Joona I Palaste: "Re: [OT] Re: malloc + 4??"
- Next in thread: Jarno A Wuolijoki: "Re: opaque style question"
- Reply: Jarno A Wuolijoki: "Re: opaque style question"
- Reply: E. Robert Tisdale: "Re: opaque style question"
- Maybe reply: CBFalconer: "Re: opaque style question"
- Reply: Keith Thompson: "Re: opaque style question"
- Reply: Capstar: "Re: opaque style question"
- Maybe reply: Joe Wright: "Re: opaque style question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|