Re: Promoting unsigned long int to long int



On Jun 30, 5:07 pm, j...@xxxxxxxxxxx (Jens Thoms Toerring) wrote:

Using unsigned long should be completely ok.

Ok.

And j gets set to ULONG_MAX (unsigned integers "wrap around").
That will keep you in this loop for a loooong time and you will
try to access elements of your array that don't exist, rather
likely resulting in a crash.

Yeah, I notice that too.

The simplest solution is to just bail out of the function if
left is equal to right - there's nothing to sort in that case.

You mean :

void quicksort (void quicksort(vector **parent_vpa, ulong left, ulong
right, uchar
axis)
{
ulong i, j;

if (left == right)
{
i = left;
j = right;

while (i <= j)
{
...
}
if (left < j)
{
quicksort(parent_vpa, left, j, axis);
}

if (i < right)
{
quicksort(parent_vpa, i, right, axis);
}

}
else
return;

.