"David Bourgeois" <address@hidden> wrote:
(A full compilable example would be nice. It's always hard to guess
the various missing pieces when trying to reproduce other people's
problems.)
Replacing the 2 lines
length = (p->inIdx) - (p->outIdx);
length %= FIFO_SIZE;
by
length = (((p->inIdx) - (p->outIdx)) % FIFO_SIZE);
completely broke my code.
The difference between both is that in the first case, the entire
computation is trimmed down to a uint8_t result immediately, while in
the second case, the intermediate results are computed as `int'. Note
the change in signedness: the implicit promotion of a uint8_t argument
to an int expression makes the expression signed. I guess that's what
broke your code.
The IMHO equivalent single-line expression would be
length = (uint8_t)(unsigned)((p->inIdx) - (p->outIdx)) / FIFO_SIZE;
even though GCC still generates somewhat different code for that.