--- In [EMAIL PROTECTED], "Ram Jois" <[EMAIL PROTECTED]> wrote:
>
> Hello Indika,
>
> If you can use function pointer for a function with 1 or 2
> arguments, why do you think you cannot use function pointer
> for function which takes multiple arguements.
>
> Please find sample test program which uses function pointer
> to a function which takes multiple arguments.
> I hope this will be of some help to you.Right I guess ???
>
> I have verified it to be working on SOLARIS OS using gcc.
>
> #include<stdio.h>
> #include<stdarg.h>
> void sum(char *str,int num_args, ...);
>
> int main()
> {
> void (*fptr_var_arg)(char *str,int var ,... );
> fptr_var_arg = sum;
> sum("sum is %d\n",4,10,13,15,20);
> return 0;
> }
>
> void sum(char *str,int num_args, ...)
> {
> va_list ptr;
> int sum=0,i;
> va_start(ptr,num_args);
> for(i=0;i<num_args;i++)
> sum += va_arg(ptr,int);
> printf(str,sum);
> va_end(ptr);
> }
<snip>
Yet the original problem was: why doesn't gcc accept two functions
with variadic parameter lists if one function doesn't have any
parameters at all?
Someone pointed out that variadic function always have to have at
least one argument. I haven't studied the ANSI C standard in ages, so
I didn't post this suspicion earlier. Yet I'm pretty sure that this is
the reason why the original problem occurs.
Regards,
Nico