R
raphfrk
Does the va_list system automatically convert types? If a long is
passed, but va_arg is told that the input is actually an int, will the
conversion happen automatically?
For example, will this program always output the following, even
though long longs are passed rather than ints? If all va_arg did was
pop from the stack, then there could be problems.
Output:
1
2
3
Code:
#include <stdio.h>
#include <stdarg.h>
void va_func( int numargs , ... );
int main( int argc, int **argv )
{
va_func( 3 , (long long)1 , (long long)2 , (long long)3 );
}
void va_func( int numargs , ... )
{
va_list vp;
va_start( vp , numargs );
int x;
while( numargs > 0 )
{
x = va_arg( vp , int );
printf( "%d\n" , x );
numargs --;
}
va_end( vp );
}
passed, but va_arg is told that the input is actually an int, will the
conversion happen automatically?
For example, will this program always output the following, even
though long longs are passed rather than ints? If all va_arg did was
pop from the stack, then there could be problems.
Output:
1
2
3
Code:
#include <stdio.h>
#include <stdarg.h>
void va_func( int numargs , ... );
int main( int argc, int **argv )
{
va_func( 3 , (long long)1 , (long long)2 , (long long)3 );
}
void va_func( int numargs , ... )
{
va_list vp;
va_start( vp , numargs );
int x;
while( numargs > 0 )
{
x = va_arg( vp , int );
printf( "%d\n" , x );
numargs --;
}
va_end( vp );
}