Texas Instruments TMS320C2x User Manual page 202

Optimizing c compiler digital signal processor
Hide thumbs Also See for TMS320C2x:
Table of Contents

Advertisement

qsort
Syntax
Defined in
Description
Example
Array Sort
#include <stdlib.h>
void qsort(void *base, size_t nmemb, size_t size, int (*compar)
(const void *, const void * ));
qsort.c in rts.src
The qsort function sorts an array of nmemb members. Argument base points
to the first member of the unsorted array; argument size specifies the size of
each member.
This function sorts the array in ascending order.
Argument compar points to a function that compares key to the array ele-
ments. The comparison function should be declared as:
int
cmp(ptr1, *ptr2)
void *ptr1, *ptr2;
The cmp function compares the objects that ptr1 and ptr2 point to and returns
one of the following values:
< 0 if *ptr1 is less than *ptr2
0 if *ptr1 is equal to *ptr2
> 0 if *ptr1 is greater than *ptr2
In the following example, a short list of integers is sorted with qsort.
#include
<stdlib.h>
int list[ ] = {3, 1, 4, 1, 5, 9, 2, 6};
int idiff (const void *, const void *);
main( )
{
qsort (list, 8, 1, idiff);
/* after sorting, list[ ]= ={ 1, 1, 2, 3, 4, 5, 6, 9} */
}
int idiff (const void *i1, const void *i2)
{
return *(int *)i1 − *(int *)i2;
Run-Time-Support Functions
qsort
7-43

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the TMS320C2x and is the answer not in the manual?

This manual is also suitable for:

Tms320c2xxTms320c5x

Table of Contents