M
MisterE
// Is any of this not portable correct etc?
#include <stdlib.h>
typedef struct b
{
int f;
} B;
//Should pointers to pointers be avoided or nothing wrong with this:
int compare( const void *arg1, const void *arg2 )
{
B **b1;
B **b2;
b1 = (B **)arg1;
b2 = (B **)arg2;
//And are there any reasons to use 1 of these lines over the other:
return ((**b1).f - (**b2).f);
//return (*b1)->f - (*b2)->f;
}
int main (int argc, char *argv[])
{
B **list;
int j = 100;
list = malloc(sizeof(B *)*j);
if (list == NULL) return -1;
while(j)
{
j--;
list[j] = malloc(sizeof(B));
if (list[j] == NULL) return -2;
list[j]->f = j;
}
qsort(list,100,sizeof(B *),compare);
return 0;
}
#include <stdlib.h>
typedef struct b
{
int f;
} B;
//Should pointers to pointers be avoided or nothing wrong with this:
int compare( const void *arg1, const void *arg2 )
{
B **b1;
B **b2;
b1 = (B **)arg1;
b2 = (B **)arg2;
//And are there any reasons to use 1 of these lines over the other:
return ((**b1).f - (**b2).f);
//return (*b1)->f - (*b2)->f;
}
int main (int argc, char *argv[])
{
B **list;
int j = 100;
list = malloc(sizeof(B *)*j);
if (list == NULL) return -1;
while(j)
{
j--;
list[j] = malloc(sizeof(B));
if (list[j] == NULL) return -2;
list[j]->f = j;
}
qsort(list,100,sizeof(B *),compare);
return 0;
}