Cannot Dereference a void *

A void * pointer cannot be dereferenced. For example, the compiler “knows” that a pointer to int refers to four bytes of memory on a machine with four-byte integers, but a pointer to void simply contains a memory address for an unknown data type—the compiler does not know the precise number of bytes to which the pointer refers and the data type. The compiler must know the data type to determine the number of bytes to dereference for a particular pointer—for a pointer to void, this number of bytes cannot be determined.


Image Common Programming Error 8.5

Assigning a pointer of one type to a pointer of another (other than void *) without using a cast (normally a reinterpret_cast) is a compilation error.



Image Common Programming Error 8.6

The allowed operations on void * pointers are: comparing void * pointers with other pointers, casting void * pointers to other pointer types and assigning addresses to void * pointers. All other operations on void * pointers are compilation errors.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.214.32