English
Language : 

CC78K0S Datasheet, PDF (230/520 Pages) NEC – C Compiler Ver.1.30 or Later Language
CHAPTER 10 LIBRARY FUNCTIONS
5-16 qsort (normal model only)
Utility Functions
FUNCTION
The qsort function sorts the members of a specified array using a quicksort algorithm.
HEADER
stdlib.h
FUNCTION PROTOTYPE
void qsort(void *base,size_t nmemb,size_t size,
int (*compare)(const void *,const void *));
Function
qsort
Arguments
base ... Pointer to array to be
sorted
nmemb ... Number of
members in the array
size ... Size of an array
member
compare ... Pointer to function
used to compare two keys
None
Return Value
EXPLANATION
• The qsort function sorts the members of the array pointed to by base in ascending order. The array pointed
to by base consists of nmemb number of members each of that has the size specified by size.
• The function pointed to by compare takes two arguments (array elements 1 and 2), compares the two
arguments, and returns:
• The array element 1 as the 1st argument and array element 2 as the 2nd argument
Negative value if the 1st argument is less than the 2nd argument
0 if both arguments are equal
Positive integer if the 1st argument is greater than the 2nd argument
• If the two array elements are equal, the element nearest to the top of the array will be sorted first.
• When the -ZR option is specified, the function passed to the argument of the qsort function must be a pascal
function.
230
User’s Manual U14872EJ1V0UM