Talk:c/algorithm/qsort

GNU and CRT versions
Could we mention in the Note section that C11 function differs from the one in Microsoft's CRT ?

C11 Annex K:

Microsoft's interface:

There is also GNU on Linux:

And a different one in FreeBSD's:

The return type and constraint handler notwithstanding, GNU's version is compatible with C11's. Sadly, both Microsoft and FreeBSD use a different parameters order, and even worse, so does their comparison function, which means the incompatibility cannot be fixed by a macro or wrapper function.

This causes a lot of confusion, so I think an addendum mentioning this would be helpful in the article.

Babbage (talk) 15:32, 23 August 2022 (PDT)


 * I would vote your proposal. Can be useful. --Space Mission (talk) 16:23, 23 August 2022 (PDT)


 * W.r.t. MS's functions. From https://open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm:
 * "Microsoft Visual Studio implements an early version of the APIs. However, the implementation is incomplete and conforms neither to C11 nor to the original TR 24731-1. For example, it doesn't provide the set_constraint_handler_s function but instead defines a _invalid_parameter_handler _set_invalid_parameter_handler(_invalid_parameter_handler) function with similar behavior but a slightly different and incompatible signature. It also doesn't define the abort_handler_s and ignore_handler_s functions, the memset_s function (which isn't part of the TR), or the rsize_max macro. The Microsoft implementation also doesn't treat overlapping source and destination sequences as runtime-constraint violations and instead has undefined behavior in such cases"
 * Not sure if there would be a good place for a general note like this? But yeah, it's best assumed that MS doesn't implement annex K --Ybab321 (talk) 01:36, 24 August 2022 (PDT)