by L. Spiro » Tue Jul 28, 2009 7:54 pm
It is not just that. Recursion causes slower code and leads to stack overflows.
It makes your code slower, harder to understand, and reduces its stability. It should be avoided at all costs.
As for your problem, you increase index by 4 but only increase count by 1.
If you increase index by 4 then you have increased the offset by 4. Since you are using count as an offset, it should be increased by 4 or multiplied by 4 at the end.
Since count is the same thing as index they should be merged into one variable (index).
index should be used to check if the end of the array has been reached. You have allocated 128 bytes per buffer but you operate on 512 bytes in that buffer (count 0-127 = index 0-508, as index is always count * 4).
Lose count, use index to keep track of where you are in the buffer and to check the buffer bounds, and return index as the offset (used to derive the final address).
L. Spiro
Our songs remind you of songs you’ve never heard.