in C, we can use the untyped pointer (void *) to represent general pointer that can be converted from and to other pointer type. however, can I access the value stored in a address pointed to by a void pointer like other normal pointer assignment:
int i = 3, i1 = 8,
int *ip = &i;
*ip = 5;
i1 = *ip;
why do I can't do like this with void pointer?
I want to write a function that deal with general data type by using void pointer and returns back the correct result. e.g. to write a function that will takes 1 void pointer as parameter and returns void value. after execute inside this function, I have to assign it into completed type pointer. I can do this well. but the problem is how can I determine what data type it should be converted to. if I declare and define all available data type in this function, it's seems a bad idea and it's also impossible. because the return value can only be one. how can I choose...
and the another things, I can use operator sizeof to determine address size to be converted to. but different data type may have the same size.
int i = 3, i1 = 8,
int *ip = &i;
*ip = 5;
i1 = *ip;
why do I can't do like this with void pointer?
I want to write a function that deal with general data type by using void pointer and returns back the correct result. e.g. to write a function that will takes 1 void pointer as parameter and returns void value. after execute inside this function, I have to assign it into completed type pointer. I can do this well. but the problem is how can I determine what data type it should be converted to. if I declare and define all available data type in this function, it's seems a bad idea and it's also impossible. because the return value can only be one. how can I choose...
and the another things, I can use operator sizeof to determine address size to be converted to. but different data type may have the same size.