可能重复:
未定义、未指定和实现定义的行为
未定义的行为和序列点
C、C++、Java 和 C# 中的前后递增运算符行为
我有这个代码片段:
int x = 2;
int y = x + 4 * ++x;
// what is y???
当我在c/c++中编译和测试它时,我会得到:
// C/C++
y is 15
但是通过c#我会得到
// C#
y is 14
为什么?
IL的一部分是:
locals init ([0] int32 x,
[1] int32 y)
IL_0000: nop
IL_0001: ldc.i4.2
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: ldc.i4.4
IL_0005: ldloc.0
IL_0006: ldc.i4.1
IL_0007: add
IL_0008: dup
IL_0009: stloc.0
IL_000a: mul
IL_000b: add
IL_000c: stloc.1
IL_000d: ldloca.s y