lkml.org 
[lkml]   [2004]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [RFC, 2.6] a simple FIFO implementation
    On Thu, 16 Sep 2004 17:52:47 +0200, Stelian Pop <stelian@popies.net> wrote:
    > On Thu, Sep 16, 2004 at 05:51:04PM +0200, Buddy Lucas wrote:
    >
    > > > No, because the type is *unsigned* int.
    > >
    > > Indeed, that would exactly be the reason *why* this would fail. ;-)
    > >
    > > The expression fifo->size - fifo->tail + fifo->head might be negative
    > > at some point, right? (fifo->head has wrapped to some small value and
    > > fifo->tail > fifo->size)
    >
    > And what is the value of an unsigned int holding that 'negative' value ? :)
    >

    Which unsigned int?! ;-) The expression a - b is negative for unsigned
    ints a and b where a < b. So, your unsigned ints "total" and
    "remaining" won't be negative of
    course, but they won't reflect what is actually left in the buffer;
    they will equal the
    value of len (in some cases) after fifo->head has wrapped (because of the
    unsignedness) and fifo->tail has not. Which would not be correct.


    Cheers,
    Buddy

    >
    >
    > Stelian.
    > --
    > Stelian Pop <stelian@popies.net>
    >
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 14:06    [W:0.033 / U:0.072 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site