Im programming some ring buffers and this question came to me several times.
Suppouse we have a counter and we need to reset after certain count. Ive seen several examples of ring buffers (mostly audio, wraping around r/w pointers), that do this:
x++;
if (x == SOME_NUMBER ){ // Reseting counter
x -= x;
}
is there any difference/preference in doing this:
x++;
if (x == SOME_NUMBER ){ // Reseting counter
x = 0;
}
?
This question applies to almost all kind of variable resets. In my case, besides ring buiffers, im also reseting a counter that do an average, so after i made all my measures, i reset that counter.
Besides the fact that the result may be the same (x reseting to zero), there may be some difference between one approach and the other. Is there any preference?