()已经过时了?! [英] () obsoleted?!

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

问题描述

-----开始PGP签名消息-----

哈希:RIPEMD160


有人可以解释为什么()函数参数列表与语义

任何类型的任意数量的参数在C99已被淘汰?是否有一个

合适的替换词具有相同的语义(类似于:void f(...))?


这是一个非常有用的东西(虽然,很少,但它是)。它在POSIX的某些部分使用

,例如: makecontext函数(由于C99,现在也是因为
已经过时)。建议使用使用线程而不是

*上下文函数。废话!例如,查看我的coroutine库

C: http://www.core-dump.com.hr/index.pl?node_id=422


广泛使用这些功能。并且有人可以找到一个

_efficient_方式将其翻译成线程吗?!


Bah,我可以重写它以使用GNU Pth,它具有类似的功能

到*上下文,但是没有()声明符。


我非常失望地看到在C99中删除了这个功能。在接下来的

std。他们可能会声明隐含的void *转换已经过时了......那些

两件事情都在三件事之中[1]这使得可以使用C作为

动态无类型语言。现在其中一个消失了。


[1]第三个是结构地址保证,即结构的地址

等于第一个地址会员。


-----开始PGP SIGNATURE -----

版本:GnuPG v1.0.6(GNU / Linux)

评论:有关信息,请参阅 http://www.gnupg.org


iD8DBQFCR6ihFtofFpCIfhMRA1mIAKCH46kLdH7T8 / DDCEVfOCPv8GdBugCfVDiJ

3RRmUh70zn + h3Fqx5gQX5Mw =

= 02ho

----- END PGP签名-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Can somebody explain why the () function argument list with the semantics
"any number of arguments of any type" has been obsoleted in C99? Is there a
suitable replacements with the same semantics (something like: void f(...))?

This was a _very_ useful thing (although, rarely, but it was). It is used
in some parts of POSIX, e.g. the makecontext function (which is also now
obsoleted because of C99). With the suggestion "use threads" instead of
*context functions. Nonsense! For example, look at my coroutine library for
C: http://www.core-dump.com.hr/index.pl?node_id=422

It makes extensive use of these functions. And can somebody find an
_efficient_ way to translate this into threads?!

Bah, I could just rewrite it to use GNU Pth, it has functions similar
to *context, but with no () declarators.

I was _very_ dissapointed to see this feature removed in C99. In the next
std. they''ll probably declare implicit void* conversion obsolete too.. Those
two things are among the 3 things[1] That made possible to use C as a
dynamic typeless language. Now one of them is gone.

[1] The 3rd being the struct address guarantee, i.e. the address of a struct
equals the address of its first member.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFCR6ihFtofFpCIfhMRA1mIAKCH46kLdH7T8/DDCEVfOCPv8GdBugCfVDiJ
3RRmUh70zn+h3Fqx5gQX5Mw=
=02ho
-----END PGP SIGNATURE-----

推荐答案

>有人可以解释为什么带有
> Can somebody explain why the () function argument list with the
语义的()函数参数列表任何类型的任意数量的参数。已经在C99中淘汰了?是否有合适的替换词具有相同的语义
(类似:void f(...))?
semantics "any number of arguments of any type" has been obsoleted in
C99? Is there a suitable replacements with the same semantics
(something like: void f(...))?




是的,你可以使用省略号(。 ..)表示未知数量的参数

(零或更多),但这需要至少一个已知参数,所以

这样的东西(原型):


int f(int i,...);


然后使用va_宏集来提取参数。请注意,某些

类型会转换为其他类型,您需要知道哪些类型的参数可以预期(并且编译器不会检查此类型)你!)

你还需要包括stdarg.h。


所有进一步的信息都可以通过谷歌轻松获得。


祝你好运,


-

Martijn
http://www.sereneconcepts.nl


-----开始PGP签名消息---- -

哈希:RIPEMD160


文章< 42 ********************* @ news.xs4all.nl>,Martijn写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

In article <42*********************@news.xs4all.nl>, Martijn wrote:

然后你使用va_宏集来提取参数。注意一些

Then you use the va_ set of macros to extract the arguments. Note that some



不完全是我想到的。我有这样的情况(当

写一个语言翻译时)。


无效解释(无效)

{

void(* op)();


while(1){

/ * fetch opcode并基于它初始化op * /

op(arg1,arg2,...);

}

}


然后每个被调用的函数都有它们的真正定义:


void op1(int);

void op2(int,int);

void op3(int,double);




解释器循环始终通过指针调用正确的数字并且

类型的参数。


在这种情况下,我不必乱用va_宏,而且一切都很好

是''清洁''...现在()功能已在C99中淘汰,没有任何内容

在未来版本的标准中替换它...

- ----开始PGP SIGNATURE -----

版本:GnuPG v1.0.6(GNU / Linux)

评论:有关信息请参阅 http://www.gnupg.org


iD8DBQFCR7voFtofFpCIfhMRA28BAJ94me9BORWDHCv3JZJi1z 966bbDcQCfdRBQ

9cTfIdh86oFWB5CFsi7Q8Ts =

= gqFm

----- END PGP SIGNATURE -----


Not exactly what I''m having in mind. I had the situation like this (when
writing a language interpreter).

void interpret(void)
{
void (*op)();

while(1) {
/* fetch opcode and initialize op based on it */
op(arg1, arg2, ...);
}
}

Then each of the called-by-op functions had their real definition like:

void op1(int);
void op2(int, int);
void op3(int, double);
etc.

the interpreter loop is always calling via the pointer with correct number and
types of arguments.

In this case I didn''t have to mess around with va_ macros, and everything
was ''cleaner''... Now the () feature is obsoleted in C99 with nothing to
replace it in future version of the standard...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFCR7voFtofFpCIfhMRA28BAJ94me9BORWDHCv3JZJi1z 966bbDcQCfdRBQ
9cTfIdh86oFWB5CFsi7Q8Ts=
=gqFm
-----END PGP SIGNATURE-----


Zeljko Vrba写道:
Zeljko Vrba wrote:
有人可以解释为什么带有语义的()函数参数列表
任意类型的任意数量的参数在C99已被淘汰?是否有一个具有相同语义的合适替换(类似于:void f(...))?
Can somebody explain why the () function argument list with the semantics
"any number of arguments of any type" has been obsoleted in C99? Is there a
suitable replacements with the same semantics (something like: void f(...))?




AFAIK void f(...) ;也不是C89中的有效声明。

参见 http://www.eskimo.com/~scs/C-faq/q15.9.html:


|问题15.9

|

|我的编译器不允许我声明一个函数

|

| int f(...)

| {

| }

|即没有固定的论点。

|

|标准C至少需要一个固定参数,

|在某种程度上,你可以把它交给va_start。

|

|参考文献:ANSI Sec。 3.5.4,Sec。 3.5.4.3,Sec。 4.8.1.1

| ISO秒6.5.4,Sec。 6.5.4.3,Sec。 7.8.1.1

-

Robert Bachmann< ne ** @ rbach.priv.at> ;, PGP-Key ID:0x8994A748



AFAIK void f(...); wasn''t a valid declaration in C89 either.
See http://www.eskimo.com/~scs/C-faq/q15.9.html:

| Question 15.9
|
| My compiler isn''t letting me declare a function
|
| int f(...)
| {
| }
| i.e. with no fixed arguments.
|
| Standard C requires at least one fixed argument,
| in part so that you can hand it to va_start.
|
| References: ANSI Sec. 3.5.4, Sec. 3.5.4.3, Sec. 4.8.1.1
| ISO Sec. 6.5.4, Sec. 6.5.4.3, Sec. 7.8.1.1
--
Robert Bachmann <ne**@rbach.priv.at>, PGP-Key ID: 0x8994A748


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

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