Creative用于变量参数列表函数 [英] Creative uses for variable argument list functions
问题描述
每次我看到一个变量参数列表的例子
函数它的功能是打印格式化输出。
有人举例说明函数不是一些变化吗?
of printf?
Spiros Bousbouras说:
每次我看到一个变量参数列表的例子
起到其功能的作用是打印格式化输出。
有人举例说明函数不是一些变化
的printf?
多么奇怪的问题!嗯,让我们看看......
当然很容易想出一些例子 - 但更难以获得
以及可能实际有用的示例。例如,一个
可能会计算一个使用0作为终结符的总和(因为0并不影响
总和,这不是不合理的),但为什么要这么麻烦?可能就像
一样,可以轻松编写一个例程,对数组中的前n项进行求和,这对于
来说会更有用。
我怀疑,如果对你的问题有一个很好的答案,它可能会在表达式解析的领域或类似的东西中存在
。
我期待着阅读其他答案,希望今天能比我更有创意地思考。
-
Richard Heathfield< http://www.cpax.org.uk>
电子邮件:-www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - 1999年7月29日dmr
文章< xI ************************* *****@bt.com>,
Richard Heathfield< rj*@see.sig.invalidwrote:
> Spiros Bousbouras说:
>每次我看到一个变量参数列表的例子时,它的功能就是打印格式化的输出。是否有任何人都有例子,其功能不是printf的一些变化?
多么奇怪的问题!好吧,让我们看看...
当然很容易想出一些例子 - 但更难以提出可能实际有用的例子。例如,一个
可能会使用0作为终结符来计算总和(因为0并不影响总和,这不是不合理的),但为什么要这么麻烦?有人可能会轻易地编写一个例程来对数组中的前n个项进行求和,这将更有用。
我怀疑,如果有一个好的回答你的问题,它可能会在表达式解析领域或类似的东西中存在。
我期待着阅读其他答案,希望能够从那些人那里获得答案。
今天比我更有创造力地思考。
我曾经用过的一次是写一个max函数,这将从一个数字列表中返回最大值。
Spiros Bousbouras写道:
< blockquote class =post_quotes>
>
每次我看到一个变量参数列表的例子
函数它的功能是打印格式化输出。
有人举例说明函数不是一些变化
的printf?
strcat()版本如何获取字符串列表,
可以像这样调用:
StrCatList(MyBuffer,MyBufferLen,string1,string2,st ring3,NULL);
是的,可以使用sprintf()来实现这个目的,但是strcat-喜欢的功能
(最有可能)效率更高。
-
+ --------- ---------------- + -------------------- + ------------ ----------- +
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h |
+ ------------------------- + --------- ----------- + ----------------------- +
不要 - 邮寄给我:< mailto:Th ************* @ gmail.com>
Every time I''ve seen an example of a variable argument list
function its functionality was to print formatted output. Does
anyone have examples where the function is not some variation
of printf ?
Spiros Bousbouras said:
Every time I''ve seen an example of a variable argument list
function its functionality was to print formatted output. Does
anyone have examples where the function is not some variation
of printf ?What a curious question! Well, let''s see...
It''s easy to come up with examples, of course - but rather harder to
come up with examples that might actually be useful. For example, one
might calculate a sum using 0 as a terminator (since 0 doesn''t affect
the sum, this is not unreasonable), but why bother? One might just as
easily write a routine that sums the first n items in an array, which
would be far more useful.
I suspect that, if there is a good answer to your question, it might lie
in the realms of expression-parsing or something along those lines.
I look forward to reading other answers, hopefully from people who are
thinking more creatively than me today.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
In article <xI******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:>Spiros Bousbouras said:
>Every time I''ve seen an example of a variable argument list
function its functionality was to print formatted output. Does
anyone have examples where the function is not some variation
of printf ?
What a curious question! Well, let''s see...
It''s easy to come up with examples, of course - but rather harder to
come up with examples that might actually be useful. For example, one
might calculate a sum using 0 as a terminator (since 0 doesn''t affect
the sum, this is not unreasonable), but why bother? One might just as
easily write a routine that sums the first n items in an array, which
would be far more useful.
I suspect that, if there is a good answer to your question, it might lie
in the realms of expression-parsing or something along those lines.
I look forward to reading other answers, hopefully from people who are
thinking more creatively than me today.The one time I used this was to write a "max" function, that would
return the maximum value from a list of numbers.
Spiros Bousbouras wrote:>
Every time I''ve seen an example of a variable argument list
function its functionality was to print formatted output. Does
anyone have examples where the function is not some variation
of printf ?How about a version of strcat() that takes a list of strings, which
could be called like this:
StrCatList(MyBuffer,MyBufferLen,string1,string2,st ring3,NULL);
Yes, one could use sprintf() for this, but strcat-like functionality
is (most likely) more efficient.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>
这篇关于Creative用于变量参数列表函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!