cepheid

An Aurora 4X clone
Log | Files | Refs | README

commit c1e1eafb7745db8b2958ab205defe606149005ab
parent 218983655903e16e2a0578cdefe3c8cd35ab14ac
Author: hhvn <dev@hhvn.uk>
Date:   Sun,  4 Sep 2022 19:20:06 +0100

macro for creating qsort compatible functions

Diffstat:
Msrc/body.c | 5+----
Msrc/main.h | 5+++++
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/body.c b/src/body.c @@ -51,10 +51,7 @@ body_cmp(Body *b1, Body *b2) { return (v1 == v2 ? 0 : (v1 > v2 ? 1 : -1)); } -static int -body_cmp_sort(const void *a, const void *b) { - return body_cmp(*(const Body **)a, *(const Body **)b); -} +SORT_FUNC(body_cmp, Body *); void body_sort(Body **bodies, size_t n) { diff --git a/src/main.h b/src/main.h @@ -10,6 +10,11 @@ #define ELEMS(array) (sizeof(array)/sizeof(array[0])) #define MAX(a, b) (a > b ? a : b) #define MIN(a, b) (a < b ? a : b) +#define SORT_FUNC(func, type) \ + static int \ + func##_sort(const void *a, const void *b) { \ + return func(*(type*)a, *(type*)b); \ + } /* main.c */ extern Save *save;