开发者

brackets in C struct syntax

I'm dealing with the following struct:

typedef PACKED struct {
   word         len;                 /* # of bytes to log (including len)*/
   word          type;                /* What kind of data is in this pkt */
   qword         time;                /* What time it was ge开发者_开发技巧nerated       */
   byte           data[MAX_DATA_BUFFER_SIZE];
} log_mobile_data_type;

My question is, what exactly is that last member of the struct? Is a member with a size equal to MAX_DATA_BUFFER_SIZE, or just 1 (byte)? And once I read actual data into the "data" member, does the "data" member represent the actual data, or is it just a pointer to it? Thanks!


It's a byte array of size MAX_DATA_BUFFER_SIZE; it's not a pointer, the data is stored directly in the struct.

When you copy the struct (e.g. by passing it as a normal parameter to a function) also the data will be copied, since it's a part of the struct.

(Incidentally, embedding an array into a struct in C is the only way to pass an array by value to a function)


It represents the actual data. It is an array of MAX_DATA_BUFFER_SIZE bytes.


The last member is an array of bytes with the size of the array being specified by MAX_DATA_BUFFER_SIZE


data is an array of bytes, with the size of MAX_DATA_BUFFER_SIZE.

If MAX_DATA_BUFFER_SIZE were 50, then data would be an array of 50 bytes.


data is an array of byte, with MAX_DATA_BUFFER_SIZE elements, its size would be sizeof(byte) * MAX_DATA_BUFFER_SIZE. when you access it, it is an inplace array, thus it is the actual data, not a pointer to it (though you can create a pointer to it via &a.data[0] or a.data)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜