What's void *userData exactly?
Posted
by mystify
on Stack Overflow
See other posts from Stack Overflow
or by mystify
Published on 2010-05-01T12:51:03Z
Indexed on
2010/05/01
12:57 UTC
Read the original article
Hit count: 245
c
In a C function declaration, I have seen this parameter definition:
void *userData
so, what exactly is that? My guess: the void says it can be anything arbitrary, or even nothing. Almost similar to id of objective-c. It just allows to pass in whatever data structure you like.
The star in front of userData says, that the argument must be passed in by reference.
So when using this stuff in the function body, typically it must be casted and dereferenced. So if I pass in an pointer to SomeClass instance, I would get that like this:
SomeClass *myObj = (SomeClass*)userData;
In the case I had nothing special to pass along, I would provide NULL as argument.
Are my assumptions correct? Or did I get something wrong?
© Stack Overflow or respective owner