MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / __array_max_element_impl

Function __array_max_element_impl

array/array.h:318–332  ·  view source on GitHub ↗

* @brief Internal implementation of array_max_element. * * Returns a pointer to the largest element according to `cmp` * (the first one encountered on ties), or NULL if the array is empty. */

Source from the content-addressed store, hash-verified

316 * <0, 0, or >0.
317 */
318#define array_min_element(arr, cmp) \
319 arrayp_min_element_impl((arr).data, array_size(arr), sizeof((arr).data[0]), (cmp))
320
321
322/**
323 * @brief Internal implementation of array_max_element.
324 *
325 * Returns a pointer to the largest element according to `cmp`
326 * (the first one encountered on ties), or NULL if the array is empty.
327 */
328static inline void *arrayp_max_element_impl(const void *data, size_t count, size_t elem_size,
329 int (*cmp)(const void *, const void *)) {
330 if (count == 0) {
331 return NULL;
332 }
333 unsigned char *ptr = (unsigned char *)(uintptr_t)data;
334 unsigned char *best = ptr;
335 for (size_t i = 1; i < count; i++) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected