0 < negative loop condition bug or misunderstanding on my part

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 6 22:05:23 PST 2012


On Wed, Mar 07, 2012 at 06:11:18AM +0100, ixid wrote:
> I'm writing my first basic algorithms, this one is merge sort. This
> version throws an exception when array.length - setSize is negative
> (which should be fine, the rest of my function would deal with it):
[...]

array.length is of type size_t, which is an *unsigned* integer type. If
setSize > array.length, then array.length - setSize will underflow and
become a large positive number.


T

-- 
They say that "guns don't kill people, people kill people." Well I think
the gun helps. If you just stood there and yelled BANG, I don't think
you'd kill too many people. -- Eddie Izzard, Dressed to Kill


More information about the Digitalmars-d-learn mailing list