L
Laurent Deniau
Is the following code valid:
void func(int va_flag, ...)
{
va_list va;
va_start(va, va_flag);
if (va_flag) { // indirect va_list
va_copy(va, va_arg(va, va_list));
}
// [...] code using va
va_end(va);
}
or it should absolutely be written as:
void func(int va_flag, ...)
{
va_list va;
va_start(va, va_flag);
if (va_flag) { // indirect va_list
va_list va0;
va_copy(va0, va_arg(va, va_list));
va_end(va);
va_copy(va, va0);
va_end(va0);
}
// [...] code using va
va_end(va);
}
According to the norm, only the second case is correct, otherwise va_end
would never be applied to the direct va if flag == 0. But the second
case is also more complex, even if in principle it should generate the
same code for a reasonable smart compiler (assuming va_end is a NOP).
a+, ld.
void func(int va_flag, ...)
{
va_list va;
va_start(va, va_flag);
if (va_flag) { // indirect va_list
va_copy(va, va_arg(va, va_list));
}
// [...] code using va
va_end(va);
}
or it should absolutely be written as:
void func(int va_flag, ...)
{
va_list va;
va_start(va, va_flag);
if (va_flag) { // indirect va_list
va_list va0;
va_copy(va0, va_arg(va, va_list));
va_end(va);
va_copy(va, va0);
va_end(va0);
}
// [...] code using va
va_end(va);
}
According to the norm, only the second case is correct, otherwise va_end
would never be applied to the direct va if flag == 0. But the second
case is also more complex, even if in principle it should generate the
same code for a reasonable smart compiler (assuming va_end is a NOP).
a+, ld.