[Top][All Lists]

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

Re: recent argp changes

From: Ben Pfaff
Subject: Re: recent argp changes
Date: Tue, 01 May 2007 13:50:19 -0700
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Bruno Haible <address@hidden> writes:

>> The option sorting in argp-help was based on the stability
>> of sort algorithm, therefore the test failed on systems with
>> quicksort qsort implementations.  It went unnoticed on glibc,
>> because its qsort uses adaptive algorithm, defaulting to
>> insertion sort if the number of partitions is smaller than a
>> predefined value, which happens to be true for the argp tests.
>> Use argument addresses to ensure they never compare as equal.
> However, I think this is not portable.  [...]

I don't think it's portable either.  It's really a shame that the
GNU libc manual suggests this technique without any warning about

    Warning: If two objects compare as equal, their order after
    sorting is unpredictable. That is to say, the sorting is not
    stable. This can make a difference when the comparison
    considers only part of the elements. Two elements with the
    same sort key may differ in other respects.

    If you want the effect of a stable sort, you can get this
    result by writing the comparison function so that, lacking
    other reason distinguish between two elements, it compares
    them by their addresses. Note that doing this may make the
    sorting algorithm less efficient, so do it only if necessary.
Ben Pfaff 

reply via email to

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