Here is the context of the code:
void THREAD_CC server_thread(void *arg)
{
BIO *client = (BIO *)arg;
..开发者_如何学C.
}
Does the expression (BIO *)arg
transform the void pointer arg
into a pointer that points to BIO? I'm not sure if I got this right or not.
Any help would be much appreciated!
Z.Zen
It's called a cast; it doesn't transform the pointer, it persuades the compiler to take your word that the incoming pointer (which is untyped) is actually a pointer to BIO, and to treat it as such.
Yes. (BIO *)
casts the void *
pointer (arg) to be of type BIO *
It transforms (casts) the void* into a pointer of type BIO*. It does not "point to" BIO.
Your input variable arg
is of type void. Typecasting just casts the variable of one type to another. This is useful when you pass pointers as arguments to different functions and typecast them to their original type when dereferencing them.
In the above case your typecasting arg
from (void *) type to (BIO *) type. Now you can access the members of the ponter client
like you would do to a normal BIO * pointer type.
精彩评论