Ilja Booij wrote:
Hi,

the ringbuf stuff is severly broken. C module arithmetic can be pretty akward:

(ringpos - 1) % RING_SIZE, with ringpos = 0 and RING_SIZE = 6:

-1 % 6 = -1

WTF? why isn't it 5?

I've just made a simple function to fix this, but I'm looking for a more elegant solution.

If you think compiler macros are elegant, then the elegant solution is here. :)

I've added a macro MOD(x,y) to pipe.c which calculates the modulo of x with respect y. It also works when x is negative.

Ilja

Reply via email to