表达式“BIO *client = (BIO *)arg”表示什么?意思是?
代码的上下文如下:
void THREAD_CC server_thread(void *arg)
{
BIO *client = (BIO *)arg;
...
}
表达式 (BIO *)arg
是否将 void 指针 arg
转换为指向 BIO 的指针?我不确定我是否做对了。
任何帮助将不胜感激!
禅宗
Here is the context of the code:
void THREAD_CC server_thread(void *arg)
{
BIO *client = (BIO *)arg;
...
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这称为演员表;它不会转换指针,它会说服编译器相信您所说的传入指针(无类型)实际上是指向 BIO 的指针,并如此对待它。
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.
是的。
(BIO *)
将void *
指针 (arg) 强制转换为BIO *
类型Yes.
(BIO *)
casts thevoid *
pointer (arg) to be of typeBIO *
它将 void* 转换(强制转换)为 BIO* 类型的指针。它不“指向”BIO。
It transforms (casts) the void* into a pointer of type BIO*. It does not "point to" BIO.
您的输入变量
arg
的类型为 void。 类型转换 只是将一种类型的变量转换为另一种类型。当您将指针作为参数传递给不同的函数并在取消引用它们时将它们类型转换为其原始类型时,这非常有用。在上述情况下,您将
arg
从 (void *) 类型转换为 (BIO *) 类型。现在您可以像访问普通 BIO * 指针类型一样访问 ponterclient
的成员。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 ponterclient
like you would do to a normal BIO * pointer type.