On 03/08/2012 03:39 AM, Ary Manzana wrote:
On 3/7/12 2:28 AM, Ali Çehreli wrote:
On 03/06/2012 09:11 PM, 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):
>
> template mergeSort(T)
> {
> void mergeSort(ref T[] array, const T setSize = 100)
> {
> T[][] merge;
> merge.length = array.length / setSize;
> T ii, jj;
> for(ii = 0, jj = 0;ii < array.length - setSize;ii += setSize, ++jj)

We don't know what T is, but I assume a signed type like int.

array.length is size_t, i.e. an unsigned type. Unsigned types have this
nasty habit of converting the entire expression to unsigned (that is a
rule since C). So array.length - setSize above is size_t.

Wouldn't it make more sense to convert the entire expression to signed
if there's at list one signed integer?


This is just as arbitrary as the rule that says the entire expression is converted to unsigned.

Reply via email to