c = a [b ++]的情况不等于c = a [b]; B = B + 1;

时间:2017-04-25 13:50:34

标签: c++ visual-c++ c++14 post-increment square-bracket

我几乎拔掉了所有的头发。代码说明了一切:

const float* const vertices = ...;
unsigned int j = 0;

        pair<float, float> poor;
        poor.first = vertices[j];
        poor.second = vertices[j + 1];
        CCLOG("WIT0 %f,%f", poor.first, poor.second);
        poor.first = vertices[j++];
        poor.second = vertices[j++];
        CCLOG("WIT1 %f,%f", poor.first, poor.second);

        j -= 2;

        poor = pair<float, float>(vertices[j], vertices[j + 1]);
        CCLOG("WIT2 %f,%f", poor.first, poor.second);
        poor = pair<float, float>(vertices[j++], vertices[j++]);
        CCLOG("WIT3 %f,%f", poor.first, poor.second);

结果是:

WIT0 -38.063835,32.743618
WIT1 -38.063835,32.743618
WIT2 -38.063835,32.743618
WIT3 32.743618,-38.063835 <- What about that, eh?

我总是认为代码是从左到右进行评估的。似乎这不是这里的情况。 代码在Visual Studio 2015,Win32调试模式下运行。

有人可以告诉我这是否是特定于实现的并且C ++指南尚未解决?

0 个答案:

没有答案