到底是va_end用来做什么?是否总是需要调用它呢? [英] What exactly is va_end for? Is it always necessary to call it?

查看:523
本文介绍了到底是va_end用来做什么?是否总是需要调用它呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

va_end用来 - 宏重置 arg_ptr

访问变量参数列表之后, arg_ptr 指针通常是与重置va_end用来()。我明白,如果你想再次重申列表中它是必需的,但是否真的需要,如果你不打算?难道仅仅是很好的做法,像治始终有一个默认值:开关

After accessing a variable argument list, the arg_ptr pointer is usually reset with va_end(). I understand that it is required if you want to re-iterate the list, but is it really needed if you aren't going to? Is it just good practice, like the rule "always have a default: in your switch"?

推荐答案

va_end用来是用来做清理工作。你不想破坏堆栈,你呢?

va_end is used to do cleanup. You don't want to smash the stack, do you?

男人的va_start

va_end用来()

va_end()

的va_start的每次调用()必须由va_end用来()中相同功能的相应调用相匹配。呼叫va_end用来(AP)之后的变量Ap是不确定的。列表的多个遍历,各由的va_start()va_end用来()括号内是可能的。 va_end用来()可以是宏或功能

Each invocation of va_start() must be matched by a corresponding invocation of va_end() in the same function. After the call va_end(ap) the variable ap is undefined. Multiple traversals of the list, each bracketed by va_start() and va_end() are possible. va_end() may be a macro or a function.

请注意这个词的的presence必须

该堆栈就被破坏了,因为的你不知道什么是的va_start()的。在 VA _ * 宏是为了被视为黑盒子。每个平台上每一个编译器可以为所欲为那里。它可能什么也不做,也可以做很多事情。

The stack could become corrupted because you don't know what va_start() is doing. The va_* macros are meant to be treated as black boxes. Every compiler on every platform can do whatever it wants there. It may do nothing, or it may do a lot.

一些ABI在寄存器中传递的前几ARGS,并在堆栈中剩余部分。 A 在va_arg()有可能更为复杂。您可以查找一个给定的实施如何做可变参数,这可能是有趣的,但以书面便携code,你应该把它们看作是不透明的操作。

Some ABIs pass the first few args in registers, and the remainder on the stack. A va_arg() there may be more complicated. You can look up how a given implementation does varargs, which may be interesting, but in writing portable code you should treat them as opaque operations.

这篇关于到底是va_end用来做什么?是否总是需要调用它呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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