gpt4 book ai didi

c++ - 函数反向传递参数

转载 作者:可可西里 更新时间:2023-11-01 18:25:59 27 4
gpt4 key购买 nike

这是我的功能:

void abc(char  *def, unsigned int w, unsigned int x, unsigned int y, unsigned int z)
{
printf("val 1 : %d\n", w);
printf("val 2 : %d\n", x);
printf("val 3 : %d\n", y);
printf("val 4 : %d\n", z);
}

这里是我调用这个函数的地方:

unsigned int exp[4] = { 1, 2, 3, 4 };
unsigned short count = 0;
abc(anyarray, exp[count++], exp[count++], exp[count++], exp[count++]);

这是我期望的输出:

val1 : 1
val2 : 2
val3 : 3
val4 : 4

但我得到的是完全相反的:

val1 : 4
val2 : 3
val3 : 2
val4 : 1

不知道为什么?任何帮助将不胜感激。

最佳答案

来自标准文档,5.4

Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified58) Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored. The requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full expression; otherwise the behavior is undefined.

来自标准文档本身的示例,

i = v[i++];//行为未定义

也是出于同样的原因

abc(anyarray, exp[count++], exp[count++], exp[count++], exp[count++]); 未定义..

关于c++ - 函数反向传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3844570/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com