qsort behavior with VC6 and VC7.1

C

chamois

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.
 
I

Ismo Salonen

chamois said:
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
 
P

peter koch

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
 
C

chamois

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.
 
P

Peter

Ismo Salonen said:
chamois wrote:
This is OT here, probably microsoft.public.vstudio.general is better.


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

Peter

chamois said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top