S
skillzero
Is it safe to get the address of a va_list parameter to a function,
later dereference it to pass to va_arg, and have the original va_list
variable updated correctly? The case I'm worried about is when va_list
is an array type. Taking the address of a local variable va_list
that's an array type will be the same as the passing the name, but
taking the address of an array type that's a function parameter will
give the address of the function parameter pointer value. For example:
void MyFunction1( const char *format, va_list args )
{
MyFunctionCore( format, &args );
}
void MyFunctionCore( const char *format, va_list *args )
{
MyFunctionCore1( format, args ); // Pulls 2 int's off the va_list (1
and 2)
MyFunctionCore2( format, args ); // Pulls the next 2 int's off the
va_list (3 and 4)
}
void MyFunctionCore1( const char *format, va_list *args )
{
int x, y;
x = va_arg( *args, int );
y = va_arg( *args, int );
}
void MyFunctionCore2( const char *format, va_list *args )
{
int a, b;
a = va_arg( *args, int );
b = va_arg( *args, int );
}
I also want it to work for the case when the va_list is a local
variable:
void MyFunction2( const char *format, ... )
{
va_list args;
va_start( args, format );
MyFunctionCore( format, &args );
va_end( args );
}
later dereference it to pass to va_arg, and have the original va_list
variable updated correctly? The case I'm worried about is when va_list
is an array type. Taking the address of a local variable va_list
that's an array type will be the same as the passing the name, but
taking the address of an array type that's a function parameter will
give the address of the function parameter pointer value. For example:
void MyFunction1( const char *format, va_list args )
{
MyFunctionCore( format, &args );
}
void MyFunctionCore( const char *format, va_list *args )
{
MyFunctionCore1( format, args ); // Pulls 2 int's off the va_list (1
and 2)
MyFunctionCore2( format, args ); // Pulls the next 2 int's off the
va_list (3 and 4)
}
void MyFunctionCore1( const char *format, va_list *args )
{
int x, y;
x = va_arg( *args, int );
y = va_arg( *args, int );
}
void MyFunctionCore2( const char *format, va_list *args )
{
int a, b;
a = va_arg( *args, int );
b = va_arg( *args, int );
}
I also want it to work for the case when the va_list is a local
variable:
void MyFunction2( const char *format, ... )
{
va_list args;
va_start( args, format );
MyFunctionCore( format, &args );
va_end( args );
}