I have the following function

void Schedule::fillUpHomeAwayArray(fixture *s_, int idx, int teamsInDiv, int *homeTeamList, int *awayTeamList) {

int curDiv = s_[idx].div_;
int curTeam = s_[idx].homeID_;
int listIdx = 0;
int *curList = homeTeamList;
curList[listIdx] = curTeam;
listIdx++;

while(s_[idx].div_ == curDiv) {
// ** cout << idx << endl;
if(curTeam != s_[idx].homeID_) {
curTeam = s_[idx].homeID_;
curList[listIdx] = curTeam;
listIdx++;
}

if(listIdx == teamsInDiv / 2) {
curList = awayTeamList;
listIdx = 0;
}
idx++;

} // while


}


It works fine (as expected) in Debug mode (I am using VC++ vers 6).

But when I run it in release mode, I don't get the same results. It looks as if idx is taking on strange values, and so the values returned are uninitialised.

BUT, if I uncomment the cout (see line // **), it works in release mode, the same as in debug mode.

Two questions.

1. Why does it work in debug mode and not release.
2. Why does adding the cout make it work in release mode.

Thanks