char str [1]和char * str在这种情况下的区别?(Difference between char str[1] and char *str in this context?)

编程入门 行业动态 更新时间:2024-10-09 10:25:33
char str [1]和char * str在这种情况下的区别?(Difference between char str[1] and char *str in this context?)

在研究一些代码时,我遇到了以下结构:

/* PACKET format: * * clientRandom - 20 byte buffer * yLen - 4 bytes (LoHi integer) * yData - yLen byte buffer * * Total length = 24 + yLen bytes */ typedef struct packetFormat { char clientRandom[20]; uint32 yLen; char yData[1]; }packetFormat;

为什么第三个字段没有声明为char *yData因为它是一个可变长度的char缓冲区?

While studying some code I encountered the following struct:

/* PACKET format: * * clientRandom - 20 byte buffer * yLen - 4 bytes (LoHi integer) * yData - yLen byte buffer * * Total length = 24 + yLen bytes */ typedef struct packetFormat { char clientRandom[20]; uint32 yLen; char yData[1]; }packetFormat;

Why the third field not declared as char *yData since its a char buffer of variable length?

最满意答案

它似乎是一个叫做struct hack的东西。

It seems to be a thing called struct hack.

更多推荐

本文发布于:2023-07-04 09:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1022350.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在这种情况下   区别   str   char   Difference

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!