3 ms·
Could be a catch that while this kind of constructs work OK for local lists, you have to be aware when passing the struct between applications or processes comp
by scoutt 8y ago
Could be a catch that while this kind of constructs work OK for local lists, you have to be aware when passing the struct between applications or processes compiled with different packing but using the same struct definition with non-aligned members.
struct foo { uint8_t data[3]; struct wl_list link; };
For an application link member may be at offset 3 while for another it would be at offset 4.
That may be the reason link should be put as the first member, and a simple cast would let you walk the list.
- AstralStorm 8y agoUsually it does not matter as you keep items of the same type or know the type and exact compiler. Unless you want to write them somewhere or put it as part of API and ABI. Which you probably shouldn't.
- scoutt 8y agoIt's true that types has something to do with it, but the main issue is padding. While I can keep the same type (i.e. uint8_t), it's the padding following uint8_t var[3] that may vary according on packing options when compiling. http://www.catb.org/esr/structure-packing/#_structure_alignment_and_padding http://www.catb.org/esr/structure-packing/#_structure_alignm...