[cprg]$ cat test.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int i=10;
printf("i=%d\ni++=%d\n++i=%d\n",i,i++,++i);
return 0;
}
[cprg]$ make
gcc -g -Wall -o test test.c
test.c: In function ‘main’:
test.c:7: warning: operation on ‘i’ may be undefined
test.c:7: warning: operation on ‘i’ may be undefined
[cprg]$ ./test
i=12
i++=11
++i=12
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会发生这件事.请问有谁可以详细解释我这里发生了什么?
C没有定义函数调用参数的评估顺序.你在那里遇到麻烦;).
更新:
澄清定义的内容和不定义的内容:
函数指示符的评估顺序,实际参数和实际参数中的子表达式是未指定的,但在实际调用之前有一个序列点.
从ISO/IEC 9899:1999,第6.5.2.2节,函数调用