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.
更多推荐
发布评论