S
sinbad
i have a common function which takes variable parameters as an argument,
depending on the type (the first arg) i want to call the appropriate
function with rest of the param list, is there any way to do this or
any better approach. i'm trying to avoid the switch() statement
below.
void
common_func(int type, ...);
void
do_one(int x, int y);
void
do_two(char a, char b);
void
do_any();
void
common_func(int type, ...)
{
switch(type) {
case 1;
do_one(); /* pass 2,3 */
break;
case 2:
do_two(); /* pass 5,6 */
break;
default:
do_any();
}
return;
}
int main()
{
comon_func(1, ,2 ,3);
comon_func(2, ,5 ,6);
}
depending on the type (the first arg) i want to call the appropriate
function with rest of the param list, is there any way to do this or
any better approach. i'm trying to avoid the switch() statement
below.
void
common_func(int type, ...);
void
do_one(int x, int y);
void
do_two(char a, char b);
void
do_any();
void
common_func(int type, ...)
{
switch(type) {
case 1;
do_one(); /* pass 2,3 */
break;
case 2:
do_two(); /* pass 5,6 */
break;
default:
do_any();
}
return;
}
int main()
{
comon_func(1, ,2 ,3);
comon_func(2, ,5 ,6);
}