In my C programming, I use opaque-pointers to struct as a way to enforce abstraction and encapsulation of my code, in that manner :
interface_header.h:
typedef struct s_mytype t_mytype;
defs_header.h:
struct s_mytype
{
/* Actual definition of the struct */
};
My problem I want to use a simple type as t_mytype
(char
for example), but not inform the interface about that. I can't just use typedef char t_mytype
, since that would expose the the internals of the type.
I could just use void pointers, but at the cost of type-checking, and I'd rather avoid that.
Doing two typedef wont work either, since that throw an typedef redefinition with different types
from the compiler.
I am also considering doing a struct with only one member, which will be my simple type, but would that be an overkill ?
Thanks for your answers.