Velocity Reviews > Variable number of parameters in a function call?

# Variable number of parameters in a function call?

Felix Kater
Guest
Posts: n/a

 10-09-2004
Hi,

is it possible to define a function in a way that when calling it I can
insert as many arguments as I want? (I would neither like to define a
function with 50 default arguments nor prepare a pointer array each time
before calling the function and pass the array, though.)

I imagine function calls like this:

f(a,b,c);
f(d,e,f,g,h);
f(a,
f(b,
c,
f(g,h,i),
e,
g,
i,
c);

Felix

Malcolm
Guest
Posts: n/a

 10-09-2004

"Felix Kater" <(E-Mail Removed)> wrote
>
> is it possible to define a function in a way that when calling it I can
> insert as many arguments as I want?

void foo(int N, ...)

Look up stdarg in your documentation to see how to access the arguments

You must have some way of telling the function how many arguments you have
passed, which means the first argument must be of fixed type.

Merrill & Michele
Guest
Posts: n/a

 10-09-2004
> "Felix Kater" <(E-Mail Removed)> wrote

>>f(a,b,c);
>>f(d,e,f,g,h);
>>f(a,
> >f(b,
>> c,
>> f(g,h,i),
>>e,
> >g,
> > i,
>>c);

> >
> > is it possible to define a function in a way that when calling it I can
> > insert as many arguments as I want?

> "Malcolm wrote:
> void foo(int N, ...)
>
> Look up stdarg in your documentation to see how to access the arguments
>
> You must have some way of telling the function how many arguments you have
> passed, which means the first argument must be of fixed type.
>

Is it possible that you're asking this question not knowing the nuts and
bolts of recursion? MPJ

Artie Gold
Guest
Posts: n/a

 10-10-2004
Merrill & Michele wrote:
>>"Felix Kater" <(E-Mail Removed)> wrote

>
>
>>>f(a,b,c);
>>>f(d,e,f,g,h);
>>>f(a,

>
> > >f(b,
> >> c,
> >> f(g,h,i),
> >>e,
> > >g,
> > > i,
> >>c);

>
>
>>>is it possible to define a function in a way that when calling it I can
>>>insert as many arguments as I want?

>
>
>>"Malcolm wrote:
>>void foo(int N, ...)
>>
>>Look up stdarg in your documentation to see how to access the arguments
>>
>>You must have some way of telling the function how many arguments you have
>>passed, which means the first argument must be of fixed type.
>>

>
>
> Is it possible that you're asking this question not knowing the nuts and
> bolts of recursion? MPJ
>
>

I fail to see the relevance of your comment.

?

--ag

--
Artie Gold -- Austin, Texas

"If you don't think it matters, you're not paying attention."

Merrill & Michele
Guest
Posts: n/a

 10-10-2004

>> >>"Felix Kater" <(E-Mail Removed)> wrote
> >>>f(a,b,c);
> >>>f(d,e,f,g,h);
> >>>f(a,
> > > >f(b,
> >>> c,
> >>> f(g,h,i),
> >>>e,
> >> >g,
> > > > i,
> > >>c);

> >>>is it possible to define a function in a way that when calling it I can
> >>>insert as many arguments as I want?

> >>"Malcolm wrote:
> >>void foo(int N, ...)
> >>
> >>Look up stdarg in your documentation to see how to access the arguments
> >>
> >>You must have some way of telling the function how many arguments you

have
> >>passed, which means the first argument must be of fixed type.
> >>

> > MPJ wrote:
> >
> > Is it possible that you're asking this question not knowing the nuts and
> > bolts of recursion? MPJ
> >
> >

> "Artie Gold" wrote : I fail to see the relevance of your comment. ?

The sentence you appended, although followed by a question mark, was a
comment. The sentence I appended, previous to yours, was a question, as
properly indicated by the question mark. If Felix the Cat is just a guy who
knows animated soft porn as opposed to set theory, then this thread can
gladly continue without my attention. MPJ

Malcolm
Guest
Posts: n/a

 10-10-2004

"Artie Gold" <(E-Mail Removed)> wrote in message
>>>>f(a,
>>>>f(b,
>>>> c,
>>>> f(g,h,i),
>>>>e,
>>>>g,
>>>> i,
>>>>c);

>>
> > Is it possible that you're asking this question not knowing the nuts and
> > bolts of recursion? MPJ
> >
> >

> I fail to see the relevance of your comment.
>

The OP is calling f() with the return value of f() as an argument. So it is
possible that what he is really after is recursion, rather than variadic
functions.

Felix Kater
Guest
Posts: n/a

 10-10-2004
Merrill & Michele:

> If Felix the Cat is just a guy who
> knows animated soft porn as opposed to set theory, then this thread
> can gladly continue without my attention.

Hm. Seems to be angry.

Felix Kater
Guest
Posts: n/a

 10-10-2004
Merrill & Michele:

> Is it possible that you're asking this question not knowing the nuts
> and bolts of recursion?

No, I am not asking for recursion.

Felix

Kenny McCormack
Guest
Posts: n/a

 10-10-2004
In article <(E-Mail Removed)>,
Felix Kater <(E-Mail Removed)> wrote:
>Merrill & Michele:
>
>> Is it possible that you're asking this question not knowing the nuts
>> and bolts of recursion?

>
>No, I am not asking for recursion.
>
>Felix

Then why do you give an example of f(...,f(...),...) ?

It is certainly possible, of course, that this has nothing to do with the
stated question (how to use the varargs capability of stdarg.h), but it
acts as a potential decoy on people's attention.

Felix Kater
Guest
Posts: n/a

 10-11-2004
Kenny McCormack:

> it
> acts as a potential decoy on people's attention.

I took this example to offer you the possibility to look for solutions
suitable to my problem. With this I wanted to be sure that the provided
solution (which I was looking for) could handle nested situations as
well.

Felix