【发布时间】:2009-11-22 18:17:12
【问题描述】:
我有一个列表,我希望能够在其中放置不同的类型。我有一个函数可以返回索引处的当前值:
void *list_index(const List * list, int index) {
assert(index < list->size);
return list->data[index];
}
数组中有多种类型,例如:
typedef struct structA { List *x; char *y; List *z; } structA;
typedef struct structB { List *u; char *w; } structB;
现在为了从数组中获取数据:
structA *A;
structB *B;
for(j=0... ) {
A = list_index(list, j);
B = list_index(list, j);
}
但是现在我如何找出返回值的类型呢? typeof 可以做到这一点吗(我正在使用 GCC btw)?
这甚至可能吗,还是我必须做出某种不同的构造?
【问题讨论】: