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 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
(2,849 Views)
I had the same problem and I solved it when i change the calling convention in the options/build option.
Let me know if it works.

ArnO
0 Kudos
Message 2 of 3
(2,849 Views)
Thanks, ArnO! It worked.
Another way to solve the problem (without changing the defaults) was simply adding __cdecl in definitions:
int __cdecl CompareShorts(const void *a, const void *b)
0 Kudos
Message 3 of 3
(2,849 Views)