473,472 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

qsort behavior with VC6 and VC7.1

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.

Feb 27 '07 #1
5 1478
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
Feb 27 '07 #2
On Feb 27, 11:46 am, "chamois" <laurentpa...@yahoo.frwrote:
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

Feb 27 '07 #3
On 27 fév, 12:43, Ismo Salonen <nob...@another.invalidwrote:
>
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.

Feb 27 '07 #4

"Ismo Salonen" <no****@another.invalidwrote in message
news:SP**************@read3.inet.fi...
chamois wrote:
This is OT here, probably microsoft.public.vstudio.general is better.

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

Mar 2 '07 #5

"chamois" <la**********@yahoo.frwrote in message
news:11**********************@s48g2000cws.googlegr 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.

Mar 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: William Buch | last post by:
I have a strange problem. The code isn't written by me, but uses the qsort function in stdlib. ALWAYS, the fourth time through, the memory location of variable list (i.e. mem location = 41813698)...
13
by: buda | last post by:
I had some spare time and decided to try to implement the standard library qsort. This is a pretty simpleminded attempt, but it seems to be working. I have to point out that efficiency is not at...
7
by: Excluded_Middle | last post by:
Suppose I have a struct typdef struct foo { int age; char *name; }foo; now I made a list of foo using
32
by: John Smith | last post by:
I'm trying to figure out qsort(). I haven't seen any practical examples, only synopsis. In the code below, the array is not sorted. Can someone give me some help? #include <stdio.h> #include...
8
by: Max | last post by:
Hi everybody, suppose you have to order a list of integers which refer to points located in the 3D space. The compare() function is based on the distance that these points have with respect to...
9
by: yogeshmk | last post by:
I'm trying to write a program which sorts the strings entered by user. I run it as $./srt -sa dddd a ccc bb # -sa is options to the program s-string a-ascending and expect a bb ccc
14
by: subramanian100in | last post by:
What is meant by stable qsort ?
10
by: gauss010 | last post by:
Suppose I have an object A of type char. Each A is a buffer containing a string, and I want to sort the M strings of A using the strcmp function. The description of the qsort function says that I...
3
by: istillshine | last post by:
I wrote a compare function for qsort. I tested version 1 and version 2 (below). Version 1 worked but version 2 did not work. Why? /* * Version 1 * Compare two numbers, used in qsort. */...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.