lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Tue, Nov 15, 2022 at 8:45 AM Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
Ah sigh, do not make me weird; now i had to look.  Well yes i also
use that idiom, but then without any array field in the struct as
such (ie alloc as much as needed, place the struct at the bottom
and then ptr=&type[1] to point to thereafter).

The "data[1]" field forces alignment constraints on the 'flexible' array at the end of the structure. If you leave it off and use
"&type[1]" the pointer generated may actually not be correctly aligned for the type of 'data'.
You may not notice on a PC or an advanced ARM processor, but not all embedded CPUs can do misaligned accesses,
and they can be slower. You're definitely in undefined territory doing that.