LWN.net Logo

Quotes of the week

The Titanic sank because there was too much water onboard after all. How it got in there (Iceberg, torpedoed by the CIA (oh it did not yet exist) in retaliation for British misbehavior) would be good to know. But the message should not suggest increasing the size of the Titanic because it cannot hold all the incoming water.
-- Christoph Lameter (thanks to Florian Mickler)

Even it if is, in fact, correct, it's such an egregious violation of good style, that your good programmer's card is going to lose a big coupon and have a hole punched in it.
-- Pete Zaitcev
(Log in to post comments)

Quotes of the week

Posted May 21, 2009 2:42 UTC (Thu) by zaitcev (guest, #761) [Link]

It's worth noting that Tejun's code was correct. I became confused because the idiom -- subtracting the value from itself in order to zero it -- is not used in C often.

Quotes of the week

Posted May 21, 2009 4:32 UTC (Thu) by jzbiciak (✭ supporter ✭, #5246) [Link]

I was going to say... that's an idiom I've used for saturating counters. Or a related one for parceling a large buffer into a series of buffers with a maximum size:

while (bytes_remaining > 0)
{
    this_xfer = min(bytes_remaining, MAX_XFER);
    xfer(buffer_pointer, this_xfer);
    buffer_pointer  += this_xfer;
    bytes_remaining -= this_xfer;
}

That's essentially the same idiom.

That said, it's a very amusing quote and I'm tempted to use it elsewhere...

Quotes of the week

Posted May 21, 2009 8:28 UTC (Thu) by MisterIO (guest, #36192) [Link]

Other than being correct, to me it seems good style too actually.

Quotes of the week

Posted May 21, 2009 12:59 UTC (Thu) by ballombe (subscriber, #9523) [Link]

Well, Tejun did not go far enough with the simplification:
rq->resid_len -= min(cmd->act_len, rq->resid_len);
is strictly equivalent to
rq->resid_len = max(rq->resid_len-cmd->act_len, 0);
which you might like better.

Quotes of the week

Posted May 21, 2009 14:34 UTC (Thu) by Yorick (subscriber, #19241) [Link]

Maybe in this case but not in general.
max(a-b,0) will not work with unsigned arithmetic, but a-min(a,b) will.

Copyright © 2009, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds