0

Can anyone please explain me this? enter image description here

Apparently there is a space containing two bytes that is beeing unused after field a. Can someone tell my why is this happening and is there a way to "turn off" such behavior? I really need it to work normally.

  • You may want to read this: ["Why isn't sizeof for a struct equal to the sum of sizeof of each member?"](http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member/119128#119128). – WhozCraig Feb 19 '15 at 13:03
  • see http://www.catb.org/esr/structure-packing/#_structure_alignment_and_padding – rasmusm Feb 19 '15 at 13:23

1 Answers1

1

This IS "working normally". Your compiler aligns the second member b to optimize for speed. The default alignment for an unsigned int on your platform is 4 bytes, so padding bytes are added after a.

To turn this off, you can use pragmas depending on your compiler, but don't call this "abnormal behavior".

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625