也许这是一个糟糕的编程案例,但它表现为XLC ++从6.0升级到11.1
代码如下:
int startAt = 140;
startAt = parseAndSaveResponseINSTANTID_MODEL(response, startAt);
COUT << "After tokenize INSTANTID_MODEL startAt=" <<startAt <<ENDL;
startAt = startAt++;
startAt = parseAndSaveResponseINSTANTID_CHRON_HISTORY(response, startAt);
COUT << "After tokenize INSTANTID_MODEL startAt=" <<startAt <<ENDL;
startAt = startAt++;
startAt = parseAndSaveResponseINSTANTID_FOLLOWUP_ACTION(response, startAt);
COUT << "After tokenize TSTID_INSTANTID_FOLLOWUP_ACTION startAt=" <<startAt <<ENDL;
startAt = startAt++;
startAt = parseAndSaveResponseINSTANTID_RISK_INDICATOR(response, startAt);
COUT << "After tokenize TSTID_INSTANTID_RISK_INDICATOR startAt=" <<startAt <<ENDL;
在每个解析方法中,我们执行return (startAt + 1 + vRows * 81);
vRows在所有方法中都为零。
使用旧编译器,输出如下:
After tokenize INSTANTID_MODEL startAt=141
vRows=0
After tokenize INSTANTID_MODEL startAt=142
vRows=0
After tokenize TSTID_INSTANTID_FOLLOWUP_ACTION startAt=143
vRows=0
After tokenize TSTID_INSTANTID_RISK_INDICATOR startAt=144
但是,使用新的编译器,输出看起来像
After tokenize INSTANTID_MODEL startAt=141
vRows=0
After tokenize INSTANTID_MODEL startAt=143
vRows=0
After tokenize TSTID_INSTANTID_FOLLOWUP_ACTION startAt=145
vRows=0
After tokenize TSTID_INSTANTID_RISK_INDICATOR startAt=147
整数/回报的处理方式是否有变化?
答案 0 :(得分:2)
startAt = startAt++
是undefined behaviour。因为它是未定义的,所以编译器可以自由地给出它给出的任何结果,例如版本6.0中的结果和版本11.1中的不同结果。
- )
使用GCC,-Wsequence-point
(或-Wall
)会发出此构造的警告。不确定XLC中是否存在等效警告。