Either cmp func seems to work; cant understand how an arg1 of type int* is being resolved in the case of qsort_cmp. As far as I can figure: int* is passed to qsort_cmp where it is changed to void*, then in return statement cast to struct s*. So far no problem, but then cast object is supposed to have a member called b, which its cast type does but its instance does not...
struct s { int a, b; };
int qsort_cmp(const void *r1, const void *r2) {
return ((struct s*) r1)->b - ((struct s*) r2)->b;
}
int bsearch_cmp(const void *key, const void *r2) {
return *(int*) key - ((struct s*) r2)->b;
}
/* themap is already qsorted */
int k = 'w'//hatever;
void *ret = bsearch(&k, themap, thenumber_ofelements, sizeof(one_element), qsort_cmp);