-Wdiscarded-qualifiers at hahsmap.h:29:16
AlessVolpe opened this issue · comments
Reimplementing the library I noticed that the foreach declared int the header file discard a 'const' quilifier
warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
((key) = hashmap_iter_get_key(&__HASHMAP_UNIQUE(x, it))) &&
note: in expansion of macro ‘__HASHMAP_FOREACH’
#define hashmap_foreach(key, data, h) __HASHMAP_FOREACH(__HASHMAP_MAKE_UNIQUE(__map), (key), (data), (h))
It happens both with the normal and safe foreach, so I suppose it should happen also with those that iterate over keys and values. Does someone understand the problem better than I do?
Thanks!
I believe this is a usage issue. The key is constant, so the pointer you pass to the hashmap_foreach()
macro for the key
parameter must be a constant value. Unlike most data structure libraries available in C that use void pointers, this library will produce a compile warning like this for incorrect or unsafe usage.
const int *key; /* This is a pointer to a constant key type */
struct my_value *val;
hashmap_foreach(key, value, &map) {
/* ... */
}
I checked my code and yes: I mistakenly didn't declared the key as a constant value; I guess i "payed" my lack of experience debugging complex C code. Thank you for the correction, have a nice day!