Given sizeof(void*) >= sizeof(int), is it safe to collect ints in tree with
void *map=0;
tsearch(42, &map, int_cmp);
?
I get segfault and I see no flaws in code other then that unusial usage.
EDIT: Of course, I am not derefencing pointer, only convert back to int. Idea is that int can be fitted into void* variable, so i have no need for heap allocation.
The first parameter to tsearch must be a pointer. In this case the number 42 is interpreted as a pointer, hence the segfault. Try:
void *map=0;
int key = 42;
tsearch(&key, &map, int_cmp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With