I've been struggling with a rather weird situation.
I had to implement some ADTs in C and use them. while using the ADT i have a typedef'ed void *.
As i was trying to work with int values, trying to return an int where that void * is expected, i got the warning "return makes pointer from integer without a cast". so i figured, ill just cast it.
but then i met this thread which guided me not to do such a thing, casting an int to void *. i had to try, though. so i got this warning - "cast to pointer from integer of different size".
anyway, i realised - maybe i could just directly return int, since this is just in the usage file of the ADT. so i changed the return type - and i got the same warnings, in other places, from pretty much the same reasons, from what i can tell.
Please, help me to get rid of those warnings. what should i do in this situation? i went through some threads regarding this issue (like the one i linked), yet there is no real solution to my problem in any of them.
My problematic function: (MapKeyElement is typedef'ed void *)
static MapKeyElement copyKeyID(MapKeyElement n) {
if (!n) {
return 0;
}
int *copy = malloc(sizeof(int));
if (!copy) {
return NULL;
}
*copy = *(int *)&n;
return (void *)*copy;
}
Thank you for your time!