计算可变参数宏中的args [英] Counting args in variadic macros

查看:81
本文介绍了计算可变参数宏中的args的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算传递给

可变参数宏的参数数量?

How do you get a count of the number of arguments passed into a
variadic macro?

推荐答案

jo******@gmail.com schrieb:
jo******@gmail.com schrieb:

如何计算传递给

可变参数宏的参数数量?
How do you get a count of the number of arguments passed into a
variadic macro?



你不是一般的。

和变量函数一样,你可以传递参数号

首先...

干杯

Michael

-

电子邮件:我的是/ gmx / dot / de address。

You don''t in general.
As with variadic functions, you can pass the argument number
first...
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


jo ****** @ gmail.com 说:

如何计算传递给

可变参数宏的参数数量?
How do you get a count of the number of arguments passed into a
variadic macro?



你需要建立一个协议,调用者和被调用者之间的契约,

,这样被调用的函数知道它什么时候有处理了它的所有参数。

这可能是由一个固定的参数控制的。例如,printf

函数使用其格式字符串中的%符号来了解

它已被发送的许多参数。或者你可以使用哨兵;例如,

你可能有一堆由0(或999,或其他)终止的整数。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)

You''ll need to establish a protocol, a contract between caller and callee,
so that the called function knows when it has processed all its arguments.
This might be controlled by one of the fixed arguments. The printf
function, for example, uses the % signs in its format string to learn how
many arguments it has been sent. Or you might use a sentinel; for example,
you might have a bunch of ints terminated by a 0 (or a 999, or whatever).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


jo ****** @ gmail.com 写道:

你怎么得到一个数传递给

可变参数宏的参数数量?
How do you get a count of the number of arguments passed into a
variadic macro?



你必须决定终止遍历的标准然后只是

从那里隐含地计算它(可能涉及遍历)。

例如,对于printf(),格式字符串隐含地描述了

参数的类型和数量。没有语言

指定的方式知道这种特定的

函数特定约定。 (虽然很可能有一个

平台特定的方式来获取这些信息。)


-

Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

You have to decide on a criteria for termination of traversal then just
implicitely compute it from there (which may involve traversal.) For
example, for printf(), the format string implicitely describes exactly
what the types and number of parameters are. There is no language
specified way of knowing this count outside of that kind of
function-specific convention. (Though it is likely that there is a
platform specific way of gaining access to this information.)

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/


这篇关于计算可变参数宏中的args的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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