【发布时间】:2021-10-28 07:28:05
【问题描述】:
void* SendMsg(void* msg) {
char *result;
char tmpBuf[1000]={0};
message send_msg =*(message*)msg;//?
问题是 * 和 (*) 类型。
(消息)"参数名称";
“消息”是定制的结构。 我知道“parameterName*”是指针,接收地址。但是“*(参数)”短语从地址中获取值。我该怎么称呼它?
【问题讨论】:
-
在
=和*之间留一个空格,以纪念史前 C 运算符 =*、=+ 等。 -
我会说
declare a new variable called send_msg of type message and initialize it with msg, cast to message star dereferenced。 -
在数据流(文件或网络)中,数据通常被序列化为字节(在 C 中使用
char)。然后发送类型擦除指针 (void*) 和长度。要将此类指针转换回此处的原始类型,首先将其转换为该类型的指针message*,然后使用*-操作符取消引用。 -
(message*)msg是从void*类型到message*类型的转换(指向消息的指针)。然后:*是访问运算符 - 它使您可以访问指针指向的值。也看看here -
所以这等于 "*message (parameter)" 对吗?