命名参数 [英] Named parameters

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

问题描述

你好,


有没有关于向C添加命名参数的讨论?我喜欢在我的Python和Ada代码中使用它们并且可以在

C中看到它们的用处。我可以设想一个实现命名将基于

在原型上,参数排序可以在

链接阶段之前解决(因此,无需处理更改链接器)。


只是好奇。我做了一些谷歌搜索,找不到任何参考,

,但这是一个不起眼的话题。


感谢您的信息,


Adam Ruth

解决方案

2003年10月29日19:35:21 -0800, ow *** @ hotmail.com (Adam Ruth)写在

comp.lang.c:

你好,

有没有关于向C添加命名参数的讨论?我喜欢在我的Python和Ada代码中使用它们,并且可以看到它们在
C中的用处。我可以设想一个实现,其中命名将基于原型并且参数排序可以是在链接阶段之前解决了(因此,无需更改链接器)。

只是好奇。我做了一些谷歌搜索,找不到任何参考,
但这是一个不起眼的话题。

感谢您的信息,
Adam Ruth




偶尔会讨论,在新闻组中,它是

topical,即news:comp.std.c,其中讨论了该语言的过去,现在,

和未来的ANSI / ISO / IEC标准。这里的主题并不是真正的主题,其主题是实际上的C语言。


从来没有得到过多的支持过去,它会打破大量的现有代码。谷歌之前在讨论comp.std.c.


-

Jack Klein

主页: http://JK-Technology.Com



comp.lang.c的常见问题解答 http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++ ftp:// snurse -l.org/pub/acllc-c++/faq


ow * **@hotmail.com (Adam Ruth)写道:

你好,

有没有任何关于向C添加命名参数的讨论?我喜欢在我的Python和Ada代码中使用它们,并且可以看到它们在
C中的用处。我可以设想一个实现,其中命名将基于原型并且参数排序可以是在链接阶段之前解决了(因此,无需更改链接器)。




谢谢,但我们的参数已经*具有*名称: - ): - p


我假设你的意思是在哪里,如果你有

原型:


void foo(int bar,int baz,int quux);


然后你可以调用foo()为:


foo (baz = 15,quux = 42,bar = 32);


即按任意顺序,只要它们被命名。


实际上我们现在已经有了类似于
结构和数组的初始化器的东西,但我想没有人关心

使用它进行函数调用。我也不是,FWIW。但是我在

标准版的未来版本中看到它们并不会感到惊讶。


如果你真的很想要它,并不是非常难以

编写你自己的预处理器,这将适当地转换这样的调用

。 :-)


-

Micah J. Cowan
mi***@cowan.name


On Thu,2003年10月30日05:04:43 +0000,Jack Klein写道:
< blockquote class =post_quotes> 2003年10月29日19:35:21 -0800, ow***@hotmail.com (亚当Ruth)在
comp.lang.c中写道:

你好,

有没有关于向C添加命名参数的讨论?我喜欢在我的Python和Ada代码中使用它们,并且可以看到它们在
C中的用处。我可以设想一个实现,其中命名将基于原型并且参数排序可以是在链接阶段之前解决了(因此,无需更改链接器)。

只是好奇。我做了一些谷歌搜索,找不到任何参考,
但这是一个不起眼的话题。

感谢您的信息,
Adam Ruth



偶尔会讨论

过去从未有过太多的支持,
它会打破巨大的现有代码的数量。




它不一定会破坏任何现有代码。只需

就可以为它提供一个语法,这在C99中是一个

语法错误。例如:


int foo(int bar,int baz){

...

int main(void){

...

返回foo(baz:15,bar:-23);

}


随着语法的变化:


argument-expression-list:

argument-expression

argument-expression-list" ;," argument-expression

argument-expression:

assignment-expression

identifier":"赋值表达式

另一个问题是否特别有用。在函数定义中使用

默认参数,我认为它可能会很高兴。


-Sheldon


Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I''ve done some googling and can''t find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth

解决方案

On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.com (Adam Ruth) wrote in
comp.lang.c:

Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I''ve done some googling and can''t find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth



It has been discussed occasionally, on the newsgroup where it is
topical, namely news:comp.std.c, which discusses the past, present,
and future ANSI/ISO/IEC standard for the language. It is not really
on-topic here, where the topic is the C language as it actually is.

There has never been much support for it in the past, and it would
break an enormous amount of existing code. Google for prior
discussions on comp.std.c.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


ow***@hotmail.com (Adam Ruth) writes:

Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).



Thanks, but our parameters already *have* names :-) :-p

I''m assuming you mean something like where if you have the
prototype:

void foo(int bar, int baz, int quux);

Then you could call foo() as:

foo(baz = 15, quux = 42, bar = 32);

That is, in any order, provided they are named.

We actually already have something similar for initializers of
structs and arrays now, but I guess nobody cared enough about
using it for function calls. I don''t really, either, FWIW. But I
wouldn''t really be surprised to see them in a future version of
the Standard.

If you really want it, it wouldn''t be extremely difficult to
write your own preprocessor which would translate such calls
appropriately. :-)

--
Micah J. Cowan
mi***@cowan.name


On Thu, 30 Oct 2003 05:04:43 +0000, Jack Klein wrote:

On 29 Oct 2003 19:35:21 -0800, ow***@hotmail.com (Adam Ruth) wrote in
comp.lang.c:

Hello,

Has there ever been any talk to adding named parameters to C? I enjoy
using them in my Python and Ada code and can see their usefulness in
C. I can envision an implementation where the naming would be based
upon a prototype and the parameter ordering could be worked out before
the linking phase (thus, no need to deal with changing a linker).

Just curious. I''ve done some googling and can''t find any references,
but it is a bit of an obscure topic.

Thanks for the info,

Adam Ruth



It has been discussed occasionally

There has never been much support for it in the past,
and it would break an enormous amount of existing code.



It wouldn''t necessarily break any existing code. It is just
necessary to come up with a syntax for it that would be a
syntax error in C99. For example:

int foo (int bar, int baz) {
...
int main (void) {
...
return foo (baz:15, bar:-23);
}

With grammar changes:

argument-expression-list:
argument-expression
argument-expression-list "," argument-expression

argument-expression:
assignment-expression
identifier ":" assignment-expression
Whether it''s particularly useful is another question. With
default arguments in the function definition, I think it
probably would be a nice to have.

-Sheldon


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

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