4
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by Narue
0

I usually create a structure (with malloc'd arrays if required) and either define the function with that typedef or as a void pointer.

Void pointers are a powerful way to pass literally anything to a function, but usually in those cases you need to also pass some enum or int describing what you are passing to the function.

0

any other method by which i can pass variable no. of arguments to a function :)

i know one method is thru va_arg related macros...is there any other method....wot wud u do...if the code skeleton looks something like this...

int sum_fun(int num_arg,...)
{

....
...
...


}


main()
{

printf("%d",sum_fun(4,4,5,6,7));
printf("%d",sum_fun(8,1,2,3,4,5,6,9,10));
...
..
..
}
0

i know one method is thru va_arg related macros...is there any other method....wot wud u do...if the code skeleton looks something like this...

int sum_fun(int num_arg,...)
{

....
...
...


}


main()
{

printf("%d",sum_fun(4,4,5,6,7));
printf("%d",sum_fun(8,1,2,3,4,5,6,9,10));
...
..
..
}

If you're using the ... notation for variable parameters, the only portable option for processing those parameters is the varargs macros. You could rewrite those macros to do the same thing, but that's silly and strictly tied to the compiler.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.