I've been looking through a program called hickit, and at one point (count.c, function starts at line 105), and they call a macros function (kavl_insert) from the Klib library as follows:
static void hk_count_nei2_core(int32_t n_pairs, struct cnt_nei2_aux *a, int r1, int r2) { struct cnt_nei2_aux *root = 0; int32_t i, j, left; unsigned cl; left = 0; kavl_insert(nei2, &root, &a[0], 0); ... Looking at the Klib library (more specifically, in kavl.h), this function (I think) is defined as follows:
#define __KAVL_INSERT(suf, __scope, __type, __head, __cmp) \ __scope __type *kavl_insert_##suf(__type **root_, __type *x, unsigned *cnt_) { \ Later on in the kavl.h file there is this standalone line (line 322):
#define kavl_insert(suf, proot, x, cnt) kavl_insert_##suf(proot, x, cnt) I don't have much technical knowledge with C (just learned parts as they were relevant), and I'm wondering how this works. The casing is different, and there is the "__" precursor in the #define line. How does this work?
__are different. There must be an actualkavl_insertdefined somewhere.kavl_insert_nei2(that is,kavl_insert_##sufwithsuf = nei2) calls it, maybe not.__scopeand__typeare the parameters of the macro. Judging by the name,__typeis the return type (here*is always added to the type), but to be certain you have to see how the macro is called.