确定子程序的参数计算顺序 [英] Determining subroutine argument evaluation order

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

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/11657100/is-this-undefined-behavior-or-implementation-defined\">Is这种不确定的行为或执行的定义?

我C语言编写的程序决定了子程序参数的计算顺序。

I am writing a program in C that determines the order in which subroutine arguments are evaluated.

我至今如下:

int i=1;
printf("%d %d %d\n", i++, i++, i);

但我不知道如果我在正确的道路上或会更容易在不同的语言像Ruby来写。

but I'm not sure If I am on the correct path or would it be easier to write in a different language like Ruby.

我怎么能写C(或Ruby)的程序决定了子程序参数的计算顺序?

How can I write a program in C (or Ruby) that determines the order in which subroutine arguments are evaluated?

推荐答案

参数评价printf()函数的顺序是的未指定。所以你不能确定可移植性以何种顺序它们进行评估。如果这是你想要的东西来决定,那么也许你会选择一种语言,其中评估的顺序的明确

The order of evaluation of arguments to printf() function is unspecified. So you can't determine portably in which order they are evaluated. If that's what you want to determine then perhaps you'd choose a language where the order of evaluation is well-defined.

此外,您的code的未定义行为为您修改 I 不止一次没有插入顺序点。

Besides, your code has undefined behaviour as you modify i more than once without an intervening sequence point.

这篇关于确定子程序的参数计算顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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