Quantcast
Channel: Recent posts
Viewing all articles
Browse latest Browse all 415

QSort - works only if disregarding advice in documentation

$
0
0

I need to sort an array of custom-type elements. I thought qsort might be a good tool for that. To get started I ignored all advice given in the qsort-documentation (https://software.intel.com/en-us/node/679798): I did _not_ provide an Interface for qsort specific to my type. I did _not_ "USE IFPORT". I did _not_ declare the compare function  "external" (but everything is in the same module). I tried it out and found it works nicely!

But because of the warnings in the documentation I´m worried that this may be unsafe, so I started changing it to the recommended way: put in "USE IFPORT" (at module Level), added an Interface (using !DIR$ ATTRIBUTES ALIAS:'qsort' with no underscore as this is 64 bit), moved the compare function out of the module and declared it "external". Now when the compare function is called the first time the second argument is invalid.

It´s interesting that in the sample given in the documentation it says:
! Passing "element_type" objects, it's called first with the pair (1, <invalid>),
! and the second item has a address well before the beginning of "C".
and further down:
! SEGV on access to C2

I wondered about this before changing my implementation, now it suddenly makes sense!

Finally I tested the sample code given (using 32 bit), and it fails in the same way!

Now my question is: What is the safe/recommended way to sort my custom-type array?

My Compiler Version is 17.0.0.109 on VS/Windows.

Thanks!


Viewing all articles
Browse latest Browse all 415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>