attractivechaos / khashl

Generic hash table library in C
19 stars 0 forks source link

kh_key error in uint32_t set when compile #3

Closed slw287r closed 4 months ago

slw287r commented 4 months ago

Some issue with set:

// set error KHASHL_SET_INIT(KH_LOCAL, kh_t, kh, uint32_t, kh_hash_uint32, kh_eq_generic)

// map is okay // KHASHL_MAP_INIT(KH_LOCAL, kh_t, kh, uint32_t, int, kh_hash_uint32, kh_eq_generic)

int main(void) { int absent; khint_t k; kh_t *h = kh_init();

    // put 
    k = kh_put(h, 20, &absent);
    k = kh_put(h, 50, &absent);

    // iterate
    kh_foreach(h, k)
            printf("h[%d]\n", kh_key(h, k));
    kh_destroy(h);
    return 0;

}


* GCC output

a.c:19:22: error: member reference base type 'uint32_t' (aka 'unsigned int') is not a structure or union printf("h[%lu]\n", kh_key(h, k)); ^~~~ ./khashl.h:388:35: note: expanded from macro 'kh_key'

define kh_key(h, x) ((h)->keys[x].key)

                  ~~~~~~~~~~~~^~~~

1 error generated. make: *** [: a] Error 1

attractivechaos commented 4 months ago

Thank you! I thought this part could be simplified but I was wrong. It is an oversight. Now reverted back to an earlier version.