在va_arg() [英] va_arg()
问题描述
你好,
我有一个关于va_arg()用法的问题:
有什么方法可以检查或确保在编译时<当有
没有下一个参数时,不会调用
va_arg()。
我明白当没有下一个参数时调用va_arg()
导致未定义的行为。
谢谢
Hello,
I have a question about va_arg() usage :
Is there any way how I can check or ensure at compile time that
va_arg() is not called when there are
no next arguments anymore.
I understood that calling va_arg() when there are no next arguments
causes an undefined behaviour.
Thanks
推荐答案
在文章< 11 ********************** @ k70g2000cwa.googlegroups .com> ;,
LIT< to ** **********@dana.comwrote:
In article <11**********************@k70g2000cwa.googlegroups .com>,
LIT <to************@dana.comwrote:
>有什么方法可以检查或确保在编译时
当没有下一个参数时,不会调用va_arg()。
>Is there any way how I can check or ensure at compile time that
va_arg() is not called when there are
no next arguments anymore.
不,你的程序必须自己解决这个问题。通常一个参数
表示有多少其他参数(如printf()中的
)或特殊值(如0)用作额外的
终止参数。
- Richard
No, your program has to work that out for itself. Typically one
of the arguments indicates how many other arguments there are (as
in printf()) or a special value (such as 0) is used as an extra
terminating argument.
-- Richard
LIT写道:
LIT wrote:
我有一个关于va_arg()用法的问题:
有什么方法可以检查或确保在编译时<当有
没有下一个参数时,不会调用
va_arg()。
I have a question about va_arg() usage :
Is there any way how I can check or ensure at compile time that
va_arg() is not called when there are
no next arguments anymore.
否 - 您必须拥有一种方法(通常基于您的第一个
参数)来确定调用va_arg的次数()。
见(例如)
http://docs.mandragor.org/files/Prog...C-faq/s15.html
和
http://docs.mandragor.org/files/Prog...faq/q15.8.html
我明白调用va_arg()当没有下一个参数时
导致未定义的行为。
I understood that calling va_arg() when there are no next arguments
causes an undefined behaviour.
是的。 (我的手册页谈到了随机错误:-)
Yep. (My manual page talks of "random errors" :-)
ma ********** @ pobox.com schreef:
ma**********@pobox.com schreef:
LIT写道:
LIT wrote:
我有一个关于va_arg()用法的问题:
有什么方法可以检查或确保在编译时<当有
没有下一个参数时,不会调用
va_arg()。
I have a question about va_arg() usage :
Is there any way how I can check or ensure at compile time that
va_arg() is not called when there are
no next arguments anymore.
否 - 你必须有一个手段(通常基于你的第一个
参数)来确定调用va_arg的次数()。
见(例如)
http://docs.mandragor.org/files/Prog...C-faq/s15.html
和
http://docs.mandragor.org/files/Prog...faq/q15.8.html
我明白调用va_arg()当没有下一个参数时
导致未定义的行为。
I understood that calling va_arg() when there are no next arguments
causes an undefined behaviour.
是的。 (我的手册页谈到了随机错误:-)
Yep. (My manual page talks of "random errors" :-)
我理解
尽管如此,如果我有这样的函数:
foo(unsigned char Nvars,...)
{
unsigned int i;
unsigned int test [10];
va_list tag;
va_start(tag,Nvars);
for(i = 0; i< Nvars; i ++)
{
test [i] = va_arg(tag,unsigned int);
}
va_end(tag)
}
和我这样做(例如,在编码期间不小心):
foo(4,x,y); (x和y是unsigned int params),
然后在编译时没有明确的方法来检测它
I understand
Nevertheless, if I have a function like this :
foo(unsigned char Nvars, ...)
{
unsigned int i;
unsigned int test[10];
va_list tag ;
va_start(tag,Nvars);
for (i=0 ; i<Nvars ; i++)
{
test[i] = va_arg(tag, unsigned int);
}
va_end(tag)
}
and I do this (eg. accidentally, during coding) :
foo(4, x, y) ; (x and y are unsigned int params),
then there is no clear means to detect this at compile time
这篇关于在va_arg()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!