22.4 “void” Pointers
The third function, gzwrite(), takes two parameters: a void* to the data and the length of the data. The return value is the amount of data written; a value of zero indicates an error.
But what exactly is void*? Did you notice that our own write() function, using the as_bytes function, created a span<byte> whose data() method returns a const byte*, which I then passed to the void* of gzwrite()? Normally, C++ always complains when you take a variable of one type and try to use it as something else. Imagine if gzwrite() took an int: then the const byte* from write wouldn't fit, and I would have had to define the parameter differently—or use a trick. And what if the data to be written are int* data or double*? Do you then ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access