1
by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages. |
1 |
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved |
2
by Francesco Paolo Lovergine
* Alligned to linux main manpages edition. |
2 |
.TH "QSORT" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" |
1
by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages. |
3 |
.\" qsort |
4 |
.SH NAME |
|
5 |
qsort \- sort a table of data
|
|
6 |
.SH SYNOPSIS |
|
7 |
.LP
|
|
8 |
\fB#include <stdlib.h>
|
|
9 |
.br
|
|
10 |
.sp
|
|
11 |
void qsort(void *\fP\fIbase\fP\fB, size_t\fP \fInel\fP\fB, size_t\fP |
|
12 |
\fIwidth\fP\fB, |
|
13 |
.br
|
|
14 |
\ \ \ \ \ \ int (*\fP\fIcompar\fP\fB)(const void *, const void *)); |
|
15 |
.br
|
|
16 |
\fP
|
|
17 |
.SH DESCRIPTION |
|
18 |
.LP
|
|
19 |
The \fIqsort\fP() function shall sort an array of \fInel\fP objects, |
|
20 |
the initial element of which is pointed to by |
|
21 |
\fIbase\fP. The size of each object, in bytes, is specified by the |
|
22 |
\fIwidth\fP argument. If the \fInel\fP argument has the value |
|
23 |
zero, the comparison function pointed to by \fIcompar\fP shall not |
|
24 |
be called and no rearrangement shall take place. |
|
25 |
.LP
|
|
26 |
The application shall ensure that the comparison function pointed |
|
27 |
to by \fIcompar\fP does not alter the contents of the array. |
|
28 |
The implementation may reorder elements of the array between calls |
|
29 |
to the comparison function, but shall not alter the contents of |
|
30 |
any individual element. |
|
31 |
.LP
|
|
32 |
When the same objects (consisting of width bytes, irrespective of |
|
33 |
their current positions in the array) are passed more than |
|
34 |
once to the comparison function, the results shall be consistent with |
|
35 |
one another. That is, they shall define a total ordering on |
|
36 |
the array. |
|
37 |
.LP
|
|
38 |
The contents of the array shall be sorted in ascending order according |
|
39 |
to a comparison function. The \fIcompar\fP argument is a |
|
40 |
pointer to the comparison function, which is called with two arguments |
|
41 |
that point to the elements being compared. The application |
|
42 |
shall ensure that the function returns an integer less than, equal |
|
43 |
to, or greater than 0, if the first argument is considered |
|
44 |
respectively less than, equal to, or greater than the second. If two |
|
45 |
members compare as equal, their order in the sorted array is |
|
46 |
unspecified. |
|
47 |
.SH RETURN VALUE |
|
48 |
.LP
|
|
49 |
The \fIqsort\fP() function shall not return a value. |
|
50 |
.SH ERRORS |
|
51 |
.LP
|
|
52 |
No errors are defined. |
|
53 |
.LP
|
|
54 |
\fIThe following sections are informative.\fP |
|
55 |
.SH EXAMPLES |
|
56 |
.LP
|
|
57 |
None. |
|
58 |
.SH APPLICATION USAGE |
|
59 |
.LP
|
|
60 |
The comparison function need not compare every byte, so arbitrary |
|
61 |
data may be contained in the elements in addition to the |
|
62 |
values being compared. |
|
63 |
.SH RATIONALE |
|
64 |
.LP
|
|
65 |
The requirement that each argument (hereafter referred to as \fIp)\fP |
|
66 |
to the comparison function is a pointer to elements of |
|
67 |
the array implies that for every call, for each argument separately, |
|
68 |
all of the following expressions are nonzero: |
|
69 |
.sp
|
|
70 |
.RS
|
|
71 |
.nf
|
|
72 |
||
73 |
\fB((char *)p - (char *)base) % width == 0
|
|
74 |
(char *)p >= (char *)base |
|
75 |
(char *)p < (char *)base + nel * width |
|
76 |
\fP
|
|
77 |
.fi
|
|
78 |
.RE
|
|
79 |
.SH FUTURE DIRECTIONS |
|
80 |
.LP
|
|
81 |
None. |
|
82 |
.SH SEE ALSO |
|
83 |
.LP
|
|
84 |
The Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI<stdlib.h>\fP |
|
85 |
.SH COPYRIGHT |
|
86 |
Portions of this text are reprinted and reproduced in electronic form |
|
87 |
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology |
|
88 |
-- Portable Operating System Interface (POSIX), The Open Group Base |
|
89 |
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of |
|
90 |
Electrical and Electronics Engineers, Inc and The Open Group. In the |
|
91 |
event of any discrepancy between this version and the original IEEE and |
|
92 |
The Open Group Standard, the original IEEE and The Open Group Standard |
|
93 |
is the referee document. The original Standard can be obtained online at |
|
94 |
http://www.opengroup.org/unix/online.html . |