Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Question on the science of language (c++)
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rizzix




PostPosted: Tue Feb 24, 2004 4:30 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue Feb 24, 2004 7:24 pm   Post subject: (No subject)

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. Smile
Andy




PostPosted: Tue Feb 24, 2004 9:32 pm   Post subject: (No subject)

wait so ur saying i can assign that memory location pointed to by the pointer to any type of variable?
Catalyst




PostPosted: Tue Feb 24, 2004 10:24 pm   Post subject: (No subject)

yes, it can be a bit messy tho with multiple castings and derefencing
wtd




PostPosted: Tue Feb 24, 2004 10:32 pm   Post subject: (No subject)

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




PostPosted: Tue Feb 24, 2004 11:32 pm   Post subject: (No subject)

interesting.. well i just had to know heh Laughing came across code using it that was implementing a garbage collector in c/c++ .. pretty cool
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: