qsort() results: implementation dependent?
- From: "Max" <iprmaster@xxxxxxxxx>
- Date: 28 Jun 2006 00:13:47 -0700
Hi everybody,
suppose you have to order a list of integers which refer to points
located in the 3D space. The compare() function is based on the
distance that these points have with respect to the origin (0,0,0). So,
using the standart qsort() function, I think this task should be
accomplished as follows:
qsort(int_vector, (size_t)no_of_points, sizeof(int), compare_function);
where
static int compare_function(void *b0, const void *b1)
{
double eps = 1e-6;
int pnt0 = *((int *)b0);
int pnt1 = *((int *)b1);
double d0 = get_distance(pnt0);
double d1 = get_distance(pnt1);
double dd = d0 - d1;
if(dd > eps)
return 1;
else if (dd < -eps)
return -1;
else
return 0.;
}
The question is: why two different qsort() implementations (AIX and
Linux) should give different results? In particular, the Linux
implementation seems to fail to to find the right order. Any hint?
Thanks
Max
.
- Follow-Ups:
- Re: qsort() results: implementation dependent?
- From: Duncan Muirhead
- Re: qsort() results: implementation dependent?
- From: Keith Thompson
- Re: qsort() results: implementation dependent?
- Prev by Date: Re: Is the output of the preprocessor deterministic ?
- Next by Date: Re: linux redirect problem
- Previous by thread: linux redirect problem
- Next by thread: Re: qsort() results: implementation dependent?
- Index(es):
Relevant Pages
|