FreeBSD Bugzilla – Attachment 132010 Details for
Bug 176197
[PATCH] Add example to qsort.3
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
0001-stdlib-Improve-qsort-3-example.patch
0001-stdlib-Improve-qsort-3-example.patch (text/plain; charset=UTF-8), 2.07 KB, created by
Christoph Mallon
on 2013-02-20 10:00:33 UTC
(
hide
)
Description:
0001-stdlib-Improve-qsort-3-example.patch
Filename:
MIME Type:
Creator:
Christoph Mallon
Created:
2013-02-20 10:00:33 UTC
Size:
2.07 KB
patch
obsolete
>From 6746bad1a6a0a72c585809e5aad361b9467035f8 Mon Sep 17 00:00:00 2001 >From: Christoph Mallon <christoph.mallon@gmx.de> >Date: Wed, 20 Feb 2013 09:52:56 +0100 >Subject: [PATCH] stdlib: Improve qsort(3) example. > >- Remove unused #include. >- Do not cast away const. >- Use the canonical idiom to compare two numbers. >- Use proper type for sizes, i.e. size_t instead of int. >- Correct indentation. >- Simplify printf("\n") to puts(""). >- Use return instead of exit() in main(). >--- > lib/libc/stdlib/qsort.3 | 22 ++++++++-------------- > 1 file changed, 8 insertions(+), 14 deletions(-) > >diff --git a/lib/libc/stdlib/qsort.3 b/lib/libc/stdlib/qsort.3 >index 83d9140..95b4248 100644 >--- a/lib/libc/stdlib/qsort.3 >+++ b/lib/libc/stdlib/qsort.3 >@@ -220,7 +220,6 @@ and then prints the sorted array to standard output is: > .Bd -literal > #include <stdio.h> > #include <stdlib.h> >-#include <string.h> > > /* > * Custom comparison function that can compare 'int' values through pointers >@@ -229,15 +228,10 @@ and then prints the sorted array to standard output is: > static int > int_compare(const void *p1, const void *p2) > { >- int *left = (int *)p1; >- int *right = (int *)p2; >+ int left = *(const int *)p1; >+ int right = *(const int *)p2; > >- if (*left < *right) >- return (-1); >- else if (*left > *right) >- return (1); >- else >- return (0); >+ return ((left > right) - (left < right)); > } > > /* >@@ -247,14 +241,14 @@ int > main(void) > { > int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 }; >- const int array_size = sizeof(int_array) / sizeof(int_array[0]); >- int k; >+ const size_t array_size = sizeof(int_array) / sizeof(int_array[0]); >+ size_t k; > >- qsort(&int_array, array_size, sizeof(int), int_compare); >+ qsort(&int_array, array_size, sizeof(int_array[0]), int_compare); > for (k = 0; k < array_size; k++) > printf(" %d", int_array[k]); >- printf("\\n"); >- exit(EXIT_SUCCESS); >+ puts(""); >+ return (EXIT_SUCCESS); > } > .Ed > .Sh ERRORS >-- >1.8.1.3 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 176197
:
132009
| 132010