[opensuse] Re: [opensuse] glibc example - qsort muppet warnings - stdlib.h expected ‘__compar_fn_t’



David C. Rankin wrote:
On 05/16/2012 08:44 AM, David C. Rankin wrote:
On 05/16/2012 06:25 AM, Andreas Jaeger wrote:
Here's a diff for the manual, I'm getting this fixed in glibc,

Andreas

diff --git a/manual/string.texi b/manual/string.texi
index 5051f54..7abf46b 100644
--- a/manual/string.texi
+++ b/manual/string.texi
@@ -1370,8 +1370,11 @@ efficiently using @code{strxfrm}.)
/* @r{This is the comparison function used with @code{qsort}.} */

int
-compare_elements (char **p1, char **p2)
+compare_elements (const void *v1, const void *v2)
@{
+ char **p1 = (char **)v1;
+ char **p2 = (char **)v2;
+
return strcoll (*p1, *p2);
@}

@@ -1462,8 +1465,11 @@ struct sorter @{ char *input; char *transformed; @};
@r{to sort an array of @code{struct sorter}.} */

int
-compare_elements (struct sorter *p1, struct sorter *p2)
+compare_elements (const void *v1, const void *v2)
@{
+ struct sorter *p1 = (struct sorter *)v1;
+ struct sorter *p2 = (struct sorter *)v2;
+
return strcmp (p1->transformed, p2->transformed);
@}


Both compiles great. Thanks Andreas. Looks like the 2.16 manual will be a good
update to the manual that probably hasn't had a good going over in quite some
time. Thanks for all you efforts there.


Andreas,

From the other thread concerning using char foo[] instead of char *foo,
couldn't the sort_strings_fast prototype (section 5.6) be improved by doing:

sort_strings_fast (char *array[], int nstrings);

instead of the current

sort_strings_fast (char **array, int nstrings);

Wouldn't that give of the same benefit of having an array of pointers to
strings instead of an array of pointer variables? It may not make any difference
here, but I thought I would pass it along anyway.


They dereference at the same speed, but the argument declaration
char **array allows for more flexibility for the caller than char *array[].


--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx



Relevant Pages

  • (patch for Bash) regex case statement
    ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: Strategy or Iterator?
    ... It would be possible to write a class that returns the variations ... GNU General Public License for more details. ... protected CombinatoricOperator(Telements, int r) { ... An integer array backing up the original one to keep track of the ...
    (comp.lang.java.programmer)
  • (patch for Bash) regex conditional tests
    ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: The question regarding type of pointers
    ... int day_of_year ... According to my understanding daytab is pointing to the whole daytab ... array i.e it is equivalent to p3. ... daytab is converted to a pointer to the first ...
    (comp.lang.c)
  • Re: Warning on assigning a function-returning-a-pointer-to-arrays
    ... This declares pfunc as a function taking no arguments and returning ... int x, y; ... Presumably pfuncwill return a pointer to a single int, ... or the first of a sequence of "array 5 of int"s. ...
    (comp.lang.c)