Reputation: 2929
So I traced a bug in Objective C++ for iOS to this code
for(int i = (maxBin - 4), max = 0; i <= (maxBin + 3); i++) {
max += (fftValLeft[i] * fftValLeft[i]);
}
The "max = 0;" doesn't happen. I moved the initialization before the loop and all is good now.
This is with Xcode 4.6.3. Is this somehow normal C behavior?
Upvotes: 1
Views: 173
Reputation: 6564
You are creating a new variable called max whose scope is only visible to the for loop. So once you come out of the loop, max value that you compute inside the loop is not visible outside of it. Hope that helps.
Upvotes: 4