2

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 generated */ 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!

1
  • Did you try sizeof and check the result? That would answer your question, would it not? Commented Jun 17, 2011 at 20:48

5 Answers 5

9

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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

Comments

0

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.

Comments

0

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.