使用一个typedef在C中使用两种不同的数据类型?

时间:2015-04-23 03:18:15

标签: c struct typedef

如果我在下面有一个结构,如果我不知道它指向的对象类型,我可以使用void **指针吗?

typedef struct A {
   ... many other things defined here 
   void ** pointer; 
};

如果指针数组可以是int或struct,是否可以将它们封装在上面的单个typedef中?我能想到的最好的解决方案是制作两个不同的typedef,每个都适应这两种可能性:

typedef struct A {
   ... many other things defined here 
   struct A ** pointer_struct; 
   int ** pointer_int; 
};

typedef struct B {
   ... same many other things defined here 
   int ** pointer_int; 
};

或者单个结构,既可以使用pointer_int,也可以使用pointer_struct null:

typedef struct A {
   ... many other things defined here 
   struct A ** pointer_struct; 
   int ** pointer_int; 
} ;   

0 个答案:

没有答案