I have a buffer that is N bytes long, where N is at least 50. This buffer is in a very specific format, where the first 4 bytes are a unsigned int representing how long the buffer is (including those four bytes). The next 16 bytes are four unsigned ints with a different meaning. The next N-20 bytes are some general purpose buffer of memory.
Right now, to set this buffer up, I do something like this:
memcpy((char*)my_buf + 0, &buf_size, 4); //buf_size is some unsigned int
memcpy((char*)my_buf + 4, &prop0, 4); //buf_size is some unsigned int
memcpy((char*)my_buf + 8, &prop1, 4); //buf_size is some unsigned int
memcpy((char*)my_buf + 12, &prop2, 4); //buf_size is some unsigned int
memcpy((char*)my_buf + 16, &prop3, 4); //buf_size is some unsigned int
//Many more bytes used as a generic buffer
However, this seems very inelegant. At this point I would like to ask the community if there is a more elegant way of assigning particular values to particular memory offsets when given an initial address.
I thought about using a struct, but IIRC a struct does not guarantee which order its members are placed in memory, and I don't know how a struct could represent the tail of the buffer which is generic memory space.