Hi. I've recently seen the use of "void *" in functions and i'm trying to figure out how it all works. If a function accepts 'void *' as a parameter that means i can pass in a pointer to anything i want, right? Like:
void Func(void * ThisPtr)
//do something with ThisPtr
int Num = 1;
int a, b, c;
My compiler accepts that but i want to understand how it works. How can i determine the scope of what the ThisPtr points to? Like if i wanted to use fwrite of something in the Func(void *) function, how could i get the size of what i passed in (besides passing it in as another parameter...)?
Could memory be allocated in function Func() like this?
ThisPtr = new char;
Or something? How could something like that be done?
Sorry for all the questions but once i get it in my head that i want to know something, i want to know all about it. :)
Using void pointers in that manner is a good way to get a core dump. The type of a pointer dictates the length of the variable it denotes, so a void* is just an address, nothing more. There are a few good uses for void*'s, but that is getting into some advanced concepts, like pseudo pointers and funky casting.