考虑以下 C - 代码:
struct ScoredGamestate
{
GameState88 gameState;
int whitePlayerScore;
};
int bestScore;
assert(scoredState->whitePlayerScore > -1000 &&
scoredState->whitePlayerScore < 1000);
if (scoredState->gameState.playerOnMove == PlayerWhite)
{
bestScore = scoredState->whitePlayerScore;
}
else
{
bestScore -(scoredState->whitePlayerScore);
}
assert(bestScore > -1000 && bestScore < 1000);
应该是合乎逻辑的,在代码之后, bestScore 总是 +/- "whitePlayerScore"
但是在我的调试器(visual studio 2010 C++ express edition)中发生了什么,“whitePlayerScore”是50,但是bestScore变成了-8908234
(第一个断言永远不会触发,但总是第二个)
这怎么会发生?