Tom*_*ica 8 c variadic-functions
我想创建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
}
Run Code Online (Sandbox Code Playgroud)
那么该放va_start ( arguments, ????? )什么?
这根本不可能。你必须有一个非可变参数,总是。在你的情况下
void free_all(void *first, ...);
Run Code Online (Sandbox Code Playgroud)
可以工作。
| 归档时间: |
|
| 查看次数: |
2216 次 |
| 最近记录: |