c – 反向传递参数的函数

这是我的功能
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++]);

这是我期望的输出

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]);未定义..

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...