What makes void pointers unique




















Another important point you should keep in mind about void pointers is that — pointer arithmetic can not be performed in a void pointer. Nice explanation. Author jojo. Rogers Guedes 8 years ago. Thank you so much guy! Jitendra 8 years ago. How does the computer know how many bytes this pointer points to? It doesn't. As such, we need to tell the computer exactly how we want to treat ptr.

In this case, as we want to zero out each byte, we want to cast it to a data type that is exactly one byte long. SparkTeach Teacher's Handbook. Previous section Introduction and Summary Next section Problems.

The asynchronous networking libraries are mostly used in multithreaded environments where different states of the requests, responses, and connection events need to be synchronized.

In those situations, explicitly deleting the user-data introduces race-conditions, which can lead to memory leaks or even deadlocks. But that approach is quite intrusive because it forces clients to inherit from a library interface. For example, the following would be valid:. Many other places where void pointers would once be used to handle multiple data types are now better done using templates, which also offer strong type checking. However, very occasionally, you may still find a reasonable use for the void pointer.

A void pointer is a pointer that can point to any type of object, but does not know what type of object it points to. A void pointer must be explicitly cast into another type of pointer to perform indirection.



0コメント

  • 1000 / 1000