Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > qsort behavior with VC6 and VC7.1

Reply
Thread Tools

qsort behavior with VC6 and VC7.1

 
 
chamois
Guest
Posts: n/a
 
      02-27-2007
Hello,

I am migrating a program from Visual C++ 6 to Visual C++ 7.1.
When I run the exe file, the behavior is different because of the
qsort function.
Indeed I have some data which are identical for my comparison
function, but they aren't sorted on the same way depending on the
version of the compiler.

It is not a disastrous problem but I would like to know if there is a
way to have an identical behaviour.

Regards,

Laurent Pajou.

 
Reply With Quote
 
 
 
 
Ismo Salonen
Guest
Posts: n/a
 
      02-27-2007
chamois wrote:
> Hello,
>
> I am migrating a program from Visual C++ 6 to Visual C++ 7.1.
> When I run the exe file, the behavior is different because of the
> qsort function.
> Indeed I have some data which are identical for my comparison
> function, but they aren't sorted on the same way depending on the
> version of the compiler.
>
> It is not a disastrous problem but I would like to know if there is a
> way to have an identical behaviour.
>
> Regards,
>
> Laurent Pajou.
>


This is OT here, probably microsoft.public.vstudio.general is better.

Anyway:

What kind of data you are sorting ?
Does the comparison routine utilize strict ordering rules
( A < B , B < C => A <C ) for every element ?

The qsort may change order of those objects having equal values.

ismo
 
Reply With Quote
 
 
 
 
peter koch
Guest
Posts: n/a
 
      02-27-2007
On Feb 27, 11:46 am, "chamois" <laurentpa...@yahoo.fr> wrote:
> Hello,
>
> I am migrating a program from Visual C++ 6 to Visual C++ 7.1.
> When I run the exe file, the behavior is different because of the
> qsort function.
> Indeed I have some data which are identical for my comparison
> function, but they aren't sorted on the same way depending on the
> version of the compiler.

This should not be a surprise to you. qsort does not specify an order
for elements that compare equal.

>
> It is not a disastrous problem but I would like to know if there is a
> way to have an identical behaviour.


Probably not if you insist on using qsort. But since you are in a C++
forum, I should mention that std::stable_sort gives a "deterministic"
sort every time. It will likely differ from your current qsort result,
but the result on the two platforms will be identical.
You really should give up qsort, by the way. It is only useful for POD
and it is likely quite a bit slower than std::sort.

/Peter

 
Reply With Quote
 
chamois
Guest
Posts: n/a
 
      02-27-2007
On 27 fév, 12:43, Ismo Salonen <nob...@another.invalid> wrote:
>
> This is OT here, probably microsoft.public.vstudio.general is better.
>
> Anyway:
>
> What kind of data you are sorting ?
> Does the comparison routine utilize strict ordering rules
> ( A < B , B < C => A <C ) for every element ?
>
> The qsort may change order of those objects having equal values.
>
> ismo


Ismo,

I sort pointers on objects and the rule ( A < B , B < C => A <C ) is
respected.
I think I will use std::stable_sort that Peter suggested.

Thansks,

Laurent.

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      03-02-2007

"Ismo Salonen" <> wrote in message
news:SPUEh.119$...
> chamois wrote:
> This is OT here, probably microsoft.public.vstudio.general is better.



just ignore such people -- this is nobodies private news group

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      03-02-2007

"chamois" <> wrote in message
news: oups.com...
> Hello,
>
> I am migrating a program from Visual C++ 6 to Visual C++ 7.1.
> When I run the exe file, the behavior is different because of the
> qsort function.
> Indeed I have some data which are identical for my comparison
> function, but they aren't sorted on the same way depending on the
> version of the compiler.
>
> It is not a disastrous problem but I would like to know if there is a
> way to have an identical behaviour.



implement your own sort or use one with deterministic behaviour.
There are other implementations of sort
-- some promise to keep to identical objects in the same order as far as I
remember.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strang behaviour std:vector and XString in VC6.0 Stijn Oude Brunink C++ 3 11-12-2004 01:38 PM
atof() and _tstof() in VC6.0 Pete C. C++ 9 06-24-2004 09:38 PM
Help!! About MySQL and VC6 Forecast C++ 0 12-31-2003 09:16 AM
const qualifier and VC6.0 Sergey Tolstov C++ 8 10-07-2003 02:42 PM
Re: qsort and structs and ptrs richard C Programming 0 08-13-2003 11:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57