Function SDL_qsort

pub unsafe extern "C" fn SDL_qsort(
    base: *mut c_void,
    nmemb: usize,
    size: usize,
    compare: Option<unsafe extern "C" fn(_: *const c_void, _: *const c_void) -> i32>,
)
Available on crate feature dep_sdl3 only.
Expand description

Sort an array.

For example:

typedef struct {
    int key;
    const char *string;
} data;

int SDLCALL compare(const void *a, const void *b)
{
    const data *A = (const data *)a;
    const data *B = (const data *)b;

    if (A->n < B->n) {
        return -1;
    } else if (B->n < A->n) {
        return 1;
    } else {
        return 0;
    }
}

data values[] = {
    { 3, "third" }, { 1, "first" }, { 2, "second" }
};

SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);

§Parameters

  • base: a pointer to the start of the array.
  • nmemb: the number of elements in the array.
  • size: the size of the elements in the array.
  • compare: a function used to compare elements in the array.

§Thread safety

It is safe to call this function from any thread.

§Availability

This function is available since SDL 3.2.0.

§See also