在va

编程入门 行业动态 更新时间:2024-10-25 22:33:42
本文介绍了在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 > ;, LIT< to ** **********@danawrote: In article <11**********************@k70g2000cwa.googlegroups >, LIT <to************@danawrote: >有什么方法可以检查或确保在编译时当没有下一个参数时,不会调用va_arg()。 >Is there any way how I can check or ensure at compile time thatva_arg() is not called when there areno 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的次数()。 见(例如) docs.mandragor/files/Prog...C-faq/s15.html 和 docs.mandragor/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 schreef: ma**********@pobox 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的次数()。 见(例如) docs.mandragor/files/Prog...C-faq/s15.html 和 docs.mandragor/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

本文发布于:2023-07-31 15:45:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1260049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:va

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!