可变数量的参数 [英] variable number of arguments
问题描述
我阅读了关于传递可变数量参数的C FAQ问题,
但它没有帮助。该示例假设所有参数都是相同的
类型。
我想创建一个函数trace可以像这样使用:
trace(" Err",errtType,lineNum,NULL)/ *其中errType是char *和
lineNum是
一个int * /
trace(" Err",lineNum,NULL);
trace( lineNum,Err,funcName,NULL)/ *其中funName是char * * /
问题是我不知道<的顺序和变量类型br />
传递的参数。
如何实现跟踪?
th***********@hotmail.com (指令)写道:
我想创建一个函数trace。可以像这样使用:
trace(" Err",errtType,lineNum,NULL)/ *其中errType是char *和
lineNum是
一个int * /
trace(" Err",lineNum,NULL);
trace(lineNum," Err",funcName,NULL)/ *其中funName是char * * /
问题是我不知道传递的参数的顺序和变量类型。
如何实现跟踪?
你不能。 trace()必须知道参数的类型,或者是
能够解决它们。
-
int main(void ){char p [] =" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz。\
\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr( ); int putchar(\
); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \
);}返回0;}
嗨
我已经写了一个相同类型的函数。但是我认为至少要有一个参数来描述以下内容是必要的。
就像printf一样,你可以:trace(char格式,。 ..);
,例如:
trace(" Err Line:%d类型:%c文件名:%s,__ LINE __,mytype,__ FILE__);
如果你愿意,我可以发送我的消息来源
多米尼克
" The Directive" <第*********** @ hotmail.com> écritdansle message de
news:84 ************************** @ posting.google.c om ...我读了关于传递可变数量的参数的C FAQ问题,
但它没有帮助。该示例假设所有参数都具有相同的类型。
我想创建一个函数trace。可以像这样使用:
trace(" Err",errtType,lineNum,NULL)/ *其中errType是char *和
lineNum是
一个int * /
trace(" Err",lineNum,NULL);
trace(lineNum," Err",funcName,NULL)/ *其中funName是char * * /
问题是我不知道传递的参数的顺序和变量类型。
如何实现跟踪?
Oups错误:
trace(char * format,...);
" DomiPi" < AK ****** @ tiscali.be> écritdansle message de
news:bt ********** @ news.worldonline.be ...嗨
我已经写了一个相同类型的函数。但是我认为至少需要一个能够描述以下内容的参数是必要的。
就像printf一样,你可以拥有:trace(char格式,......);
例如:
trace(Err Line:%d类型:%c文件名:%s,__ LINE __,mytype,__ FILE__);
如果你愿意,我可以发送我的来源>多米尼克
指令 <第*********** @ hotmail.com> écritdansle message de
新闻:84 ************************** @ posting.google.c om ... < blockquote class =post_quotes>我读了关于传递可变数量参数的C FAQ问题,
但它没有帮助。该示例假设所有参数都具有相同的类型。
我想创建一个函数trace。可以像这样使用:
trace(" Err",errtType,lineNum,NULL)/ *其中errType是char *和
lineNum是
一个int * /
trace(" Err",lineNum,NULL);
trace(lineNum," Err",funcName,NULL)/ *其中funName是char * * /
问题是我不知道传递的参数的顺序和变量类型。
如何实现跟踪?
I read the C FAQ question on passing a variable number of arguments,
but it didn''t help. The example assumes all arguments are of the same
type.
I want to create a function "trace" that can be used like this:
trace( "Err", errtType, lineNum, NULL) /* where errType is char* and
lineNum is
an int */
trace("Err", lineNum, NULL);
trace( lineNum, "Err", funcName, NULL) /* where funName is char * */
The problem is that I don''t know the order and the variable types of
the arguments passed.
How can I implement trace?
th***********@hotmail.com (The Directive) writes:
I want to create a function "trace" that can be used like this:
trace( "Err", errtType, lineNum, NULL) /* where errType is char* and
lineNum is
an int */
trace("Err", lineNum, NULL);
trace( lineNum, "Err", funcName, NULL) /* where funName is char * */
The problem is that I don''t know the order and the variable types of
the arguments passed.
How can I implement trace?
You can''t. trace() has to know the types of the arguments, or be
able to figure them out.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Hi
I already wrote a function of the same type. But I believe that it is
necessary to have at least a parameter which will describe the following.
Like does it printf, you could have: trace(char format,...);
with for example:
trace("Err Line:%d Type:%c File name:%s,__LINE__,mytype,__FILE__);
If you want, I can send my source
Dominique
"The Directive" <th***********@hotmail.com> a écrit dans le message de
news:84**************************@posting.google.c om...I read the C FAQ question on passing a variable number of arguments,
but it didn''t help. The example assumes all arguments are of the same
type.
I want to create a function "trace" that can be used like this:
trace( "Err", errtType, lineNum, NULL) /* where errType is char* and
lineNum is
an int */
trace("Err", lineNum, NULL);
trace( lineNum, "Err", funcName, NULL) /* where funName is char * */
The problem is that I don''t know the order and the variable types of
the arguments passed.
How can I implement trace?
Oups error:
trace(char *format, ...);
"DomiPi" <ak******@tiscali.be> a écrit dans le message de
news:bt**********@news.worldonline.be...Hi
I already wrote a function of the same type. But I believe that it is
necessary to have at least a parameter which will describe the following.
Like does it printf, you could have: trace(char format,...);
with for example:
trace("Err Line:%d Type:%c File name:%s,__LINE__,mytype,__FILE__);
If you want, I can send my source
Dominique
"The Directive" <th***********@hotmail.com> a écrit dans le message de
news:84**************************@posting.google.c om...I read the C FAQ question on passing a variable number of arguments,
but it didn''t help. The example assumes all arguments are of the same
type.
I want to create a function "trace" that can be used like this:
trace( "Err", errtType, lineNum, NULL) /* where errType is char* and
lineNum is
an int */
trace("Err", lineNum, NULL);
trace( lineNum, "Err", funcName, NULL) /* where funName is char * */
The problem is that I don''t know the order and the variable types of
the arguments passed.
How can I implement trace?
这篇关于可变数量的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!