我想用指针参数初始化一个链表,如下所示:
/*
* Initialize a linked list using variadic arguments
* Returns the number of structures initialized
*/
int init_structures(struct structure *first, ...)
{
struct structure *s;
unsigned int count = 0;
va_list va;
va_start(va, first);
for (s = first; s != NULL; s = va_arg(va, (struct structure *))) {
if ((s = malloc(sizeof(struct structure))) == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
count++;
}
va_end(va);
return count;
}
问题是 , 的 clang 错误type name requires a specifier or qualifier
,va_arg(va, (struct structure *))
并说类型说明符默认为 int。它还记录了(struct structure *)
和的实例化形式struct structure *
。这个,似乎被分配到s
的是int (struct structure *)
.
当从 中删除括号时,它编译得很好(struct structure *)
,但是应该初始化的结构是不可访问的。
int
当括号围绕传递给 va_arg 的类型参数时,为什么假定?我怎样才能解决这个问题?