bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: recent argp changes


From: Paul Eggert
Subject: Re: recent argp changes
Date: Tue, 01 May 2007 19:26:34 -0700
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Bruno Haible <address@hidden> writes:

> you are now assuming an in-place sorting algorithm. If a libc were
> to implement qsort by use of mergesort (and temporary storage), such
> a sorting algorithm would pass you two pointers to hol_entrys in
> different array.

A minor quibble: the C standard (both C89 and C99) does not allow such
an implementation for qsort; it requires that the arguments to the
comparison function be bona fide pointers into the
originally-specified array.

> To make this portable, I see two options:
>   - Sort an array of 'hol_entry*' instead of an array of 'hol_entry';
>     then you can be sure the hol_entrys stay in place. Or
>   - Add a field 'array_index' to the hol_entry struct. Fill these fields
>     right before calling qsort.

I agree with this suggestion.  Even though the standard requires that
qsort be in-place, it does not require that qsort must behave by
swapping elements in the naive way.  Also, it's possible that the C
library is buggy in this area (glibc used to have such a bug), as the
point is fairly obscure.  So a fix is necessary, and the two options
you mention both should work.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]