I have a class method in a library (can't change it) which takes a double void pointer as one of its arguments. The declaration is as follows:
bool Queue::pop(void **packet, int &size, unsigned short &sn)
In my application code, I want to pass this function a pointer to another kind of object, in this case a GstBuffer pointer type. It seems like I can do this without any compiler errors if I cast the pointer to (void**)
as in the following snippet but I have doubts if that will lead to correct behaviour. Is it valid to convert the pointer like this?
guint16 sn;
int size;
GstBuffer *buf;
Queue *Q = ... // create a Queue instance
Q->pop((void **)&buf, size, sn); // is this conversion valid?
size = gst_buffer_get_size(buf);
For all intents and purposes a
void
pointer can hold addresses of any object (data type), i.e. it can point to any object, and can be typecasted to any object, your code is valid, I would just use a more idiomatic cast:§7.3.12 Pointer conversions [conv.ptr]
Example:
Output:
The explicit cast is even only needed because it's a pointer to pointer otherwise the conversion would be implicit, no cast would be needed.