Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #15220

Re: Is there any way to refer to another array in qsort's compare function?

From 88888 Dihedral <dihedral88888@googlemail.com>
Newsgroups comp.lang.c
Subject Re: Is there any way to refer to another array in qsort's compare function?
Date 2011-12-29 15:40 -0800
Organization http://groups.google.com
Message-ID <20176374.1516.1325202027641.JavaMail.geo-discussion-forums@prfc16> (permalink)
References <f7d05964-b7de-45b1-afde-7ac9d7c38e9b@x34g2000prb.googlegroups.com> <chine.bleu-16CC21.05072829122011@news.eternal-september.org> <0.5c841624aedd98f7bb51.20111229141606GMT.87oburbh09.fsf@bsb.me.uk> <0.bded03ab937c20e3131a.20111229152916GMT.87fwg3bdmb.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse於 2011年12月29日星期四UTC+8下午11時29分16秒寫道:
> Ben Bacarisse <ben.u...@bsb.me.uk> writes:
> 
> > Bull in a China Blue Shop <chine...@yahoo.com> writes:
> <snip>
> >> MacOSX has qsort_r which passes a context pointer to qsort_r which, in turn, 
> >> passes it to the compare. I don't know if other implementations have this.
> >
> > It's in most modern versions of the GNU C library (apparently since
> > version 2.8) but it's not documented yet.
> 
> Argh!  I decided to write the missing man page and in so doing I found
> the following mess:
> 
> The GNU version has prototype
> 
>   void qsort_r(void *base, size_t nmemb, size_t size,
>                int (*compar)(const void *, const void *, void *),
>                void *data);
> 
> I.e. the data pointer is last and gets passed as the third argument to
> the comparison function.
> 
> The BSD version is
> 
>   void qsort_r(void *base, size_t nmemb, size_t size, void *data,
>                int (*compar)(void *, const void *, const void *));
> 
> with the data pointer as the fourth argument which gets passed as the
> first argument to the comparison function.
> 
> Microsoft decided to do this:
> 
>   void qsort_s(void *base, size_t nmemb, size_t size,
>                int (*compare)(void *, const void *, const void *),
>                void *data);
> 
> using the argument order of the GNU version and the comparison function
> of the BSD version.
> 
> Annex K of the new C standard defines an option set of library extension
> based on Microsoft's supposedly "safer" functions.  Here we find (edited
> for consistency):
> 
>   errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size,
>                  int (*compar)(const void *, const void *, void *),
>                  void *data);
> 
> which follows the GNU version except for the name and the return type!
> I don't know why the online documentation for Microsoft systems does not
> used this version.
> 
> >  I think qsort_r is probably
> > close to being reliably available on *nix type systems but I don't know
> > about Windows C libraries.
> 
> So, no.  There is no widely available qsort function that takes a data
> pointer.  If the documentation is right, you can't even use the
> quasi-standard qsort_s with Microsoft's C library.
> 
> It's a shame that we are left with this mess.  Annex K is optional, and
> is an all-or-nothing set of extensions (I may have misunderstood that)
> so qsort_s is likely to languish alongside all the other _s functions.
> qsort_r is functionally better that qsort -- the change is not a
> mythical safety advantage.
> 
> <snip>
> -- 
> Ben.

A you joking about using the lousy quicksort in the standard lib as posted
by the top post here ?

Take a look at some real applications of sorting required in the 
data compression in BWT or the DNA sequencing problem. 







problem 

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is there any way to refer to another array in qsort's compare function? Stone <stonekyx@gmail.com> - 2011-12-29 00:27 -0800
  Re: Is there any way to refer to another array in qsort's compare function? Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-29 08:57 +0000
  Re: Is there any way to refer to another array in qsort's compare function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-29 11:58 +0000
    Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-29 04:20 -0800
      Re: Is there any way to refer to another array in qsort's compare function? Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-29 12:37 +0000
        Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-29 04:48 -0800
          Re: Is there any way to refer to another array in qsort's compare function? Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-29 12:59 +0000
            Re: Is there any way to refer to another array in qsort's compare function? Geoff <geoff@invalid.invalid> - 2011-12-29 10:09 -0800
              Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-29 17:50 -0800
                Re: Is there any way to refer to another array in qsort's compare function? Geoff <geoff@invalid.invalid> - 2011-12-29 19:29 -0800
                Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-30 00:36 -0800
                Re: Is there any way to refer to another array in qsort's compare function? Bull in a China Blue Shop <chine.bleu@yahoo.com> - 2011-12-30 00:52 -0800
                Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-30 02:16 -0800
              Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-29 18:01 -0800
            Re: Is there any way to refer to another array in qsort's compare function? James Kuyper <jameskuyper@verizon.net> - 2011-12-29 13:21 -0500
        Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-30 23:18 -0800
    Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-07 23:40 -0800
      Re: Is there any way to refer to another array in qsort's compare function? pete <pfiland@mindspring.com> - 2012-01-08 07:26 -0500
        Re: Is there any way to refer to another array in qsort's compare function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-08 12:50 +0000
          Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-08 06:02 -0800
        Re: Is there any way to refer to another array in qsort's compare function? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-01-17 12:35 +0200
  Re: Is there any way to refer to another array in qsort's compare function? Bull in a China Blue Shop <chine.bleu@yahoo.com> - 2011-12-29 05:07 -0800
    Re: Is there any way to refer to another array in qsort's compare function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-29 14:16 +0000
      Re: Is there any way to refer to another array in qsort's compare function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-29 15:29 +0000
        Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-29 09:33 -0800
        Re: Is there any way to refer to another array in qsort's compare function? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-29 15:40 -0800
  Re: Is there any way to refer to another array in qsort's compare function? James Kuyper <jameskuyper@verizon.net> - 2011-12-29 10:50 -0500
  Re: Is there any way to refer to another array in qsort's compare function? pete <pfiland@mindspring.com> - 2012-01-07 20:50 -0500

csiph-web