没有第一个参数的可变参数 - va_start 中的内容是什么?
Variable arguments without first argument - what belongs in va_start?
我想制作 varargs
函数来一次释放多个指针,主要是为了清理代码。所以我有:
void free_all( ... ) {
va_list arguments;
/* Initializing arguments to store all values after last arg */
// but there are no args!
va_start ( arguments, ????? );
/* we expect the caller to send last argument as NULL **/
void* pointer = va_arg ( arguments, void* );
while( (pointer = va_arg ( arguments, void* ))!=NULL ) {
free(pointer);
}
va_end ( arguments ); // Cleans up the list
}
那么要在 va_start ( arguments, ????? )
中输入什么?
这根本不可能。您必须始终有一个非可变参数参数。在你的情况下
void free_all(void *first, ...);
可以工作。
我想制作 varargs
函数来一次释放多个指针,主要是为了清理代码。所以我有:
void free_all( ... ) {
va_list arguments;
/* Initializing arguments to store all values after last arg */
// but there are no args!
va_start ( arguments, ????? );
/* we expect the caller to send last argument as NULL **/
void* pointer = va_arg ( arguments, void* );
while( (pointer = va_arg ( arguments, void* ))!=NULL ) {
free(pointer);
}
va_end ( arguments ); // Cleans up the list
}
那么要在 va_start ( arguments, ????? )
中输入什么?
这根本不可能。您必须始终有一个非可变参数参数。在你的情况下
void free_all(void *first, ...);
可以工作。