----------------------------------- rizzix Tue Feb 24, 2004 4:30 pm Question on the science of language (c++) ----------------------------------- plz don't answer this unless you have done some study on computer language design and concepts. what does a pointer to void mean ? and you may answer this nevertheless how is a pointer to void used in a program. ----------------------------------- wtd Tue Feb 24, 2004 7:24 pm ----------------------------------- A void pointer is sort of a "generic pointer", in that it points to a location in memory, but has no type information attached to it. You could write a 32-bit integer into memory at a certain location, then read the same memory bac, but via casting to "void *" you could read it back to "float *". Basically in C at least (C++ compilers are sometimes more strict) you can cast any pointer to a void pointer, and a void pointer into any other type. I'm sure you can see the danger. :-) ----------------------------------- Andy Tue Feb 24, 2004 9:32 pm ----------------------------------- wait so ur saying i can assign that memory location pointed to by the pointer to any type of variable? ----------------------------------- Catalyst Tue Feb 24, 2004 10:24 pm ----------------------------------- yes, it can be a bit messy tho with multiple castings and derefencing ----------------------------------- wtd Tue Feb 24, 2004 10:32 pm ----------------------------------- And it's dangerous. There's a reason you have typed variables. That type name holds information about the size of a data structure. What happens if you allocate memory for a 96-bit data structure, then have a pointer for a data structure 64 bits long point to it, then free the memory for the latter? The answer is that now you have 32 bits floating around unaccounted for. Or you could free too much memory. ----------------------------------- rizzix Tue Feb 24, 2004 11:32 pm ----------------------------------- interesting.. well i just had to know heh :lol: came across code using it that was implementing a garbage collector in c/c++ .. pretty cool