开发者

What does the expression "BIO *client = (BIO *)arg" mean?

开发者 https://www.devze.com 2023-01-07 03:29 出处:网络
Here is the context of the code: void THREAD_CC server_thread(void *arg) { BIO *client = (BIO *)arg; ..开发者_如何学C.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消