Signed word lengths and indexes

Kagamin spam at here.lot
Tue Jun 15 07:38:50 PDT 2010


Steven Schveighoffer Wrote:

> On Mon, 14 Jun 2010 21:48:10 -0400, BCS <none at anon.com> wrote:
> 
> > Hello Steven,
> >
> >> div0 <div0 at users.sourceforge.net> writes:
> >>
> >>> for(uint i = end - 1; i < length; --i)
> >>> ...
> >> What does "length" represent here? It's not clear to me how "i"
> >> descending toward zero is going to break the guard condition.
> >>
> >
> > My thought exactly.
> >
> > If i<j and you --i, I'd assume i<j, if your code depends on the case  
> > where the assumption is wrong, don't ask me to do a code review because  
> > I won't sign off on it.
> >
> 
> i is unsigned, and therefore can never be less than 0.  It's actually a  
> clever way to do it that I've never thought of.
> 
> Read it more like this:
> 
> for(uint i = end - 1; i < length && i >= 0; --i)
> 
> But the i >= 0 is implicit because i is unsigned.
> 
foreach_reverse, lol


More information about the Digitalmars-d mailing list