命名参数

扫码查看
本文介绍了命名参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, 有没有关于向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 谢谢,但我们的参数已经*具有*名称: - ): - p 我假设你的意思是在哪里,如果你有 原型: void foo(int bar,int baz,int quux); 然后你可以调用foo()为: foo (baz = 15,quux = 42,bar = 32); 即按任意顺序,只要它们被命名。 实际上我们现在已经有了类似于结构和数组的初始化器的东西,但我想没有人关心 使用它进行函数调用。我也不是,FWIW。但是我在 标准版的未来版本中看到它们并不会感到惊讶。 如果你真的很想要它,并不是非常难以 编写你自己的预处理器,这将适当地转换这样的调用 。 :-) - Micah J. Cowan mi***@cowan.name 偶尔会讨论 过去从未有过太多的支持,它会打破巨大的现有代码的数量。 它不一定会破坏任何现有代码。只需 就可以为它提供一个语法,这在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 enjoyusing them in my Python and Ada code and can see their usefulness inC. I can envision an implementation where the naming would be basedupon a prototype and the parameter ordering could be worked out beforethe 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 istopical, namely news:comp.std.c, which discusses the past, present,and future ANSI/ISO/IEC standard for the language. It is not reallyon-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 wouldbreak an enormous amount of existing code. Google for priordiscussions on comp.std.c.--Jack KleinHome: http://JK-Technology.ComFAQs forcomp.lang.c http://www.eskimo.com/~scs/C-faq/top.htmlcomp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faqThanks, but our parameters already *have* names :-) :-pI''m assuming you mean something like where if you have theprototype: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 ofstructs and arrays now, but I guess nobody cared enough aboutusing it for function calls. I don''t really, either, FWIW. But Iwouldn''t really be surprised to see them in a future version ofthe Standard.If you really want it, it wouldn''t be extremely difficult towrite your own preprocessor which would translate such callsappropriately. :-)--Micah J. Cowan mi***@cowan.name 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 justnecessary to come up with a syntax for it that would be asyntax 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-expressionargument-expression-list "," argument-expressionargument-expression:assignment-expressionidentifier ":" assignment-expressionWhether it''s particularly useful is another question. Withdefault arguments in the function definition, I think itprobably would be a nice to have.-Sheldon 这篇关于命名参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 19:35
查看更多