|
|
Subscribe / Log in / New account

Nothing wrong with unsigned, properly used

Nothing wrong with unsigned, properly used

Posted Dec 11, 2008 8:45 UTC (Thu) by ldo (guest, #40946)
Parent article: Re: [PATCH] ext3: also fix loop in do_split()

Assuming I correctly understood the intent of the original version, I would have written it like:

for (i = count - 1;;)
  {
    ... body of loop ...
    if (i == 0)
        break;
    --i;
  } /*for*/

See, no problems with overflow, i stays within the valid range for an unsigned at all times.

I find that 90% of my loops tend to have an exit in the middle.


to post comments


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