yes, but the original question was to how to create a function pointer
which can hold any number of arguments

for example; 
typedef void (*foo)(int, ...);
void func1(int, ...);
void func2(int, float);

foo f1 = func1; // OK
foo f2 = func2; // NOT OK

what this shows(as i understand) is the type foo can 'only' hold
variadic functions. but since it can hold variadic functions i was
hoping that it should be able to hold a function with a certain number
of arguments....  u got the point?

so to say if somebody wanted a function pointer type that can hold 
functions with any number of arguments then is it impossible?

indika



--- 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);
> }
> 
> Thnx....Ram
> 
> On 12 Apr 2007 02:35:28 -0700, Chetan Nanda <[EMAIL PROTECTED]> wrote:
> >
> >   I think in a function accepting variable number of arguments,
there must
> > be
> > atleast one fixed argument that will be treadted as a start of
variable
> > argument list.
> > Please correct me if i am wrong
> >
> > thank
> > Chetan
> >
> > On 10 Apr 2007 23:52:00 -0700, Indika Bandara Udagedara <
> > [EMAIL PROTECTED] <indikabandara19%40yahoo.com>> wrote:
> > >
> > > function pointer to variable argument function
> > > hi,
> > >
> > > how can i define a function pointer type to a function that takes
> > variable
> > > number(0 or more) of arguments
> > >
> > > following does not work..??
> > >
> > > ////////////////////////////////////////////////////////////////////
> > >
> > > /* func ptr to function which takes 0 or more args */
> > >
> > > typedef void (*func_ptr)(...);
> > >
> > > /* functions that take 0,1 args */
> > >
> > > void foo();
> > >
> > > void foo1(int);
> > >
> > > /* assignment DOESN'T COMPILE */
> > >
> > > func_ptr pfoo = foo;
> > >
> > > func_ptr pfoo1 = foo1;
> > >
> > > gcc error:
> > >
> > > invalid conversion from `void (*)(int)' to `void (*)(...)'
> > >
> > > ///////////////////////////////////////////////////////////////////
> > >
> > > in essence, what i want is a function pointer which is capable
of taking
> > > any number of arguments.
> > >
> > > can somebody help me with this?
> > >
> > > indika
> > >
> > > ---------------------------------
> > > Need Mail bonding?
> > > Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> >
> > [Non-text portions of this message have been removed]
> >
> >  
> >
> 
> 
> [Non-text portions of this message have been removed]
>


Reply via email to