--- a/docs/Writerside/topics/array_list.h.md Thu Dec 18 12:11:30 2025 +0100 +++ b/docs/Writerside/topics/array_list.h.md Thu Dec 18 12:26:25 2025 +0100 @@ -114,6 +114,30 @@ > with `cx_array_copy_to_new()` or `cx_array_copy_to_new_a()` before adding or inserting more elements. >{style="note"} +## Sorting + +```C +#include <cx/array_list.h> + +void cx_array_qsort_c(void *array, size_t nmemb, size_t size, + cx_compare_func2 fn, void *context); + +void cx_array_sort(CxArray array, cx_compare_func fn); + +void cx_array_sort_c(CxArray array, + cx_compare_func2 fn, void *context); +``` + +With simple `cx_compare_func` functions, arrays can always be sorted with standard `qsort()`. +Sorting arrays with `cx_compare_func2` functions, however, need special support by either `qsort_r()` (GNU) or `qsort_s()` (ISO). +However, both functions come with their own challenges. +On the one hand, `qsort_r()` is not ISO standard, and on the other hand `qsort_s()` is only optional and has an incorrect parameter order in the Microsoft C library. + +To provide a platform independent solution, UCX detects if `qsort_r()` is available and implements a fallback when it is not. +You can safely use `cx_array_qsort_c()` everywhere wehere you would use `qsort_r()`. + +The functions `cx_array_sort()` and `cx_array_sort_c()` are for convenient work with arrays declared with `CX_ARRAY()`. + ## Insertion Sort ```C