函数调用中可变数量的参数? [英] Variable number of parameters in a function call?

查看:73
本文介绍了函数调用中可变数量的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否有可能以某种方式定义一个函数,在调用它时我可以

插入尽可能多的参数? (我不想定义一个带有50个默认参数的

函数,也不想在调用函数并传递数组之前每次准备一个指针数组

。)


我想象这样的函数调用:


f(a,b,c);

f(d,e, f,g,h);

f(a,

f(b,

c,

f(g,h) ,i),

e,

g,

i,

c);


Felix

解决方案



" Felix Kater"< f。****** @ gmx .net>写道


是否有可能以一种方式定义一个函数,在调用它时我可以插入尽可能多的参数?




void foo(int N,...)


在文档中查找stdarg,了解如何访问参数


你必须有一些方法告诉函数你有多少参数通过
,这意味着第一个参与者t必须是固定类型。


> Felix Kater <˚F****** @ gmx.net>写了

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

是否有可能以某种方式定义一个函数,在调用它时我可以插入尽可能多的参数?


" Malcolm写道:
void foo(int N,...)

在你的文档中查找stdarg以了解如何访问论点

你必须有一些方法告诉函数你传递了多少参数,这意味着第一个参数必须是固定类型。




是否有可能你问这个问题不知道坚果和

递归的螺栓?MPJ


Merrill& Michele写道:

" Felix Kater" f。****** @ gmx.net>写道



< blockquote class =post_quotes> f(a,b,c);
f(d,e,f,g,h);
f(a,> > f(b,
>> c,
>> f(g,h,i),
>> e,
>> ; g,
>> i,
>> c);
是否有可能以一种方式定义一个函数,当它调用它时我可以插入为我想要的许多论点?



" Malcolm写道:
void foo(int N,...)

在你的文档中查找stdarg以了解如何访问参数

你必须有一些方法告诉函数你传递了多少个参数,这意味着第一个参数必须是固定类型。



你是否有可能在问这个问题时不知道螺母和递归的螺栓? MPJ



我没有看到你评论的相关性。





- g


-

Artie Gold - 德克萨斯州奥斯汀


"如果你不要认为这很重要,你没有注意。


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

解决方案


"Felix Kater" <f.******@gmx.net> 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.


> "Felix Kater" <f.******@gmx.net> 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


Merrill & Michele wrote:

"Felix Kater" <f.******@gmx.net> 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."


这篇关于函数调用中可变数量的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆