如何使用 va_start()? [英] How to use va_start()?

查看:36
本文介绍了如何使用 va_start()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个带有可变参数的函数中,我们用函数 va_start() 初始化一个 va_list 类型的对象,'ap' 为:

In a function with variable arguments, we initialize an object of type va_list ,'ap' with the function va_start() as:

void va_start(va_list ap, parmN);

我不明白

1.什么类型的对象可以作为parMN(最后一个已知参数)传递.我已经完成了传递整数、带有格式说明符的字符串、结构等的示例.

2. parMN如何描述以下可选参数.

I don't understand

1.what type of objects can be passed as parMN(last known parameter). I've done with examples of passing integers, strings with format specifiers, structures etc.

2. How the parMN describes the following optional parameters.

推荐答案

C 标准说 va_start() 实际上是一个宏,而不是一个函数,所以它可以做一些函数做不到的事情.细节高度依赖于实现,但您可以想象它需要 parmN 的地址来确定下一个参数的堆栈地址.va_start() 不需要知道以下参数的类型,因为这些信息被传递给 va_arg(),这是另一个宏.

The C standard says that va_start() is actually a macro, not a function, so it can do things a function couldn't. The details are highly implementation dependent but you could imagine that it takes the address of parmN to determine the stack address of the next parameter. There's no need for va_start() to know about the types of the following parameters because that information is passed to va_arg(), which is another macro.

这篇关于如何使用 va_start()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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