LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of ANSI-C "qsort" function?

Hi.
I would like to sort some short integers using "qsort".
CVI returns an error message "Type error in argument 4 to `qsort'; calling convention mismatch.". I am using CVI 5.5.
I also tried some example code pieces that worked with gcc and mcc, but CVI compiler returns the same error.
A strange convention or a bug?
Thanks, Matti

Sort command:
qsort ((void *)input, (size_t)num, (size_t)sizeof(short), CompareShorts);

Comparison function:
int CompareShorts(const void *element1,const void *element2)
{
short *a1,*b1;
a1=(short *)element1;
b1=(short *)element2;
return (*a1<*b1) ? -1 : (*a1>*b1) ? 1 : 0;
}
0 Kudos
Message 1 of 3
(3,278 Views)
Duplicate post. See answer here.
0 Kudos
Message 2 of 3
(3,278 Views)
Hello

I tried the following code on CVI 5.5 and it didnt return any errors to me, give this a shot:


#include
#include

short input[5]={5,4,3,2,1};
int num=5;


int CompareShorts(const void *element1,const void *element2);

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

qsort ((void *)input, (size_t)num, (size_t)sizeof(short), CompareShorts);

return 0;
}



int CompareShorts(const void *element1,const void *element2)
{
short *a1,*b1;
a1=(short *)element1;
b1=(short *)element2;
return (*a1<*b1) ? -1 : (*a1>*b1) ? 1 : 0;
}



//=====end of code==================


Best of luck
Bilal
Bilal Durrani
NI
0 Kudos
Message 3 of 3
(3,278 Views)