Re: Practical packing for structs of bytes



On Mon, 20 Sep 2010, Michael Henry wrote:

On Sep 17, 1:19 pm, "Ersek, Laszlo" <la...@xxxxxxxxxxxxxx> wrote:
On Fri, 17 Sep 2010, Michael Henry wrote:
   uint8_t *buf = ...buffer of raw protocol bytes...;

   ProtocolHeader *p = (ProtocolHeader *) buf;

I wanted to add before: dependent on the placeholder code that provides the initializer to "buf", this may still invoke undefined behavior, in-effect implementation-dependent "structure packing" notwithstanding.

Is the undefined behavior due to alignment restrictions on the struct,

Yes, that's what I had in mind.

Cheers,
lacos