[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Undefined qsort behavior
- To: linuxgames@sunsite.dk
- Subject: Re: Undefined qsort behavior
- From: "Miguel A. Osorio" <maos@gbl.com.br>
- Date: Thu, 05 Dec 2002 17:12:47 -0200
- Delivered-to: archiver@seul.org
- Delivered-to: mailing list linuxgames@sunsite.dk
- Delivery-date: Thu, 05 Dec 2002 20:00:25 -0500
- Mailing-list: contact linuxgames-help@sunsite.dk; run by ezmlm
- References: <20021124110121.GC2021@ypisco.com> <3DE0EE31.1070904@airmail.net> <3DE1733E.6030309@gmx.de> <3DE19C32.6000009@airmail.net> <20021125191244.GD27874@fysh.org> <3DE2B388.6080201@airmail.net> <20021129180109.GB26555@fysh.org> <3DEF8287.41A19@gbl.com.br> <20021205204605.GA31724@fysh.org>
- Reply-to: linuxgames@sunsite.dk
- Sender: hornet@munge.net
Katie Lucas wrote:
>
> On Thu, Dec 05, 2002 at 02:44:55PM -0200, Miguel A. Osorio wrote:
>
> > material/texture). But the qsort man page says: "If two members
> > compare as equal, their order in the sorted array is undefined". So my
> > question is this: this "undefined order" still groups equal elements
> > together, or is the undefined *really* undefined ? For instance, if I
> > have an array: 4 2 3 1 2 4, do I *always* get: 1 2 2 3 4 4 ?
>
> "Undefined" has a very technical defintion. It means, very literally,
> the behaviour has not been specified in ANY WAY and the routine is
> free to do as it pleases with it.
>
> It could vary between library implementations, between machines with
> different CPUs, it could vary on initial conditions, sizes of the
> arrays; absolutely ANYTHING. And when it does so, you have no
> comeback.
>
> Testing it on your machine and using that undefined bahaviour is
> asking for it not to work somewhere else later. You might as well
> raise the bug against that bit of code yourself.
>
> Undefined means "don't use this, it might stop working like it does at
> any point in time".
Hum, I see. I did think in those terms, but then again, what about the
quicksort algorithm? I mean, does this undefined behavior come from the
algorithm, or specifically from the standard C lib implementation? If
the problem is the library, I could always write a qsort myself, with a
defined behavior for equal elements, but if the problem is the
algorithm, then it's no quicksort for me :)
Thank you for your attention,
Miguel A. Osorio