Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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
 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      10-09-2004

"Felix Kater" <> 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.


 
Reply With Quote
 
 
 
 
Merrill & Michele
Guest
Posts: n/a
 
      10-09-2004
> "Felix Kater" <> 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


 
Reply With Quote
 
Artie Gold
Guest
Posts: n/a
 
      10-10-2004
Merrill & Michele wrote:
>>"Felix Kater" <> 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."
 
Reply With Quote
 
Merrill & Michele
Guest
Posts: n/a
 
      10-10-2004

>> >>"Felix Kater" <> 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


 
Reply With Quote
 
Malcolm
Guest
Posts: n/a
 
      10-10-2004

"Artie Gold" <> 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.


 
Reply With Quote
 
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.
 
Reply With Quote
 
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
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      10-10-2004
In article <>,
Felix Kater <> 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.

 
Reply With Quote
 
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
Variable number of parameters on SOAP call? John Allen Ruby 2 03-03-2009 05:52 PM
variable number of parameters passed to sscanf() at runtime Andrew C++ 18 05-23-2006 07:04 PM
Class Member Data and Member Function Parameters - Should Parameters Be Data Members? Jason C++ 2 05-13-2006 07:11 AM
getting and passing variable number of parameters Michael Cohen C Programming 2 12-26-2003 12:14 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57