在我的 C 编程中,我使用 opaque-pointers 来构建结构,以这种方式强制抽象和封装我的代码:
interface_header.h:
typedef struct s_mytype t_mytype;
defs_header.h:
struct s_mytype
{
/* Actual definition of the struct */
};
我的问题我想使用一个简单的类型作为t_mytype
(char
例如),但不通知界面。我不能只使用typedef char t_mytype
,因为这会暴露类型的内部结构。我可以只使用 void 指针,但要以类型检查为代价,我宁愿避免这种情况。
做两个 typedef 也不起作用,因为这会typedef redefinition with different types
从编译器中抛出一个。
我也在考虑做一个只有一个成员的结构,这将是我的简单类型,但这会不会是矫枉过正?
感谢您的回答。