i have a question about how to use a dynamic parameter list
as in the example required.
int func2(int a,...)
{
//her i will use all the parmeters passed to the func1 function
va_list ap
va_start(ap,a);
do
{
a=(int)va_arg(ap,int);
//=> a=1,a=2,a=3,a=4,a=5;
}while(a!=0);
va_end(ap);
}
int func1(int a,...)
{
func2(a,??????)
}
int main()
{
func1(1,2,3,4,5);
}
my problem is va_list can not be used.
has anyone a idea?
Avoid using va_arg at all costs, there's much better, safer ways to do it. If in the end you really have to use it then you've probably made a bad design choice somewhere.
If all the args are the same type just pass them in a collection of some kind as master roshi pointed out.
thnx for your ideas. But this solutions are not usable so far i know, because i'm trying
to overload the linux libc library and there especially the functions
open and ioctl (see in /usr/include/unistd.h) use a dynamic parameterlist. So i need to handle
this. Because if my function should be used instead of the origin function
it need to supply the same function signature otherwise it will not be used.
Oh, that's a really crappy situation :/ The best solution I can think now is to write loads of overloads for your function, sort of like this:
1 2 3 4 5 6 7 8 9 10 11
int my_func(int a)
{
return lib_func(a);
}
int my_func(int a, int b)
{
return lib_func(a,b);
}
//etc...
EDIT: Now that I re-read your post, I think that maybe that's not what you're looking for... Could you explain a bit more? Are your functions wrappers for the library functions? Who is going to call your functions?