0

This is a simple C calculation. The first one above doesn't roll over when FilterIndex is equal to FilterDepth. In other words, FilterDepth is 15, filterIndex becomes 15, once the cpu executes this, it should be 0, but it becomes 16 and later becomes 1, never 0.

If I break the logic into two, it works. What am I missing here?

filterIndex = ((filterIndex++) % FilterDepth) ;

vs.

filterIndex++;
filterIndex=filterIndex % FilterDepth;
user4749
  • 431
  • 2
  • 6
  • 17

1 Answers1

2

This is undefined behavior in C, and thus its behavior could be anything.
You are trying to modify a value more than one time between sequence points.

Community
  • 1
  • 1
Prashant Kumar
  • 20,069
  • 14
  • 47
  • 63