#define CFG_USED(type, name, stuff) \
{ .compFunc = compare_ ## type; /* */ },
#define CFG_UNUSED(type, name, stuff) /* unused */
#define CFG_ADD(type, name, stuff) CFG_USE_ ## type (type,name,stuff)
#ifdef USING_int
#define CFG_USE_int CFG_USED
#else
#define CFG_USE_int CFG_UNUSED
#endif
####
/tmp>cat testing.c
#include
#include
static inline int compare_short(const void * a, const void * b)
{
if (*(short *)a < *(short *)b) return -1;
if (*(short *)a > *(short *)b) return 1;
return 0;
}
static inline int compare_int(const void * a, const void * b)
{
if (*(int *)a < *(int *)b) return -1;
if (*(int *)a > *(int *)b) return 1;
return 0;
}
static int foo[5]={47,11,0,8,15};
int main(int argc, char ** argv)
{
qsort(foo,sizeof(foo)/sizeof(foo[0]),sizeof(foo[0]),&compare_int);
}
/tmp>CFLAGS="-Wall -pedantic" make testing
cc -Wall -pedantic testing.c -o testing
/tmp>cc --version
cc (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/tmp>
####
static foo compare_foo(void *a, void *b) { return _inline_cmpfunc_foo(a, b); }
####
#define CFG_ADD(TYPE,NAME,STUFF) \
static int compare_ ## NAME(const void * a, const void * b) \
{ \
return _inline_cmpfunc_ ## TYPE(a,b); \
}