This is not an error. The compiler ( gcc ? ) will add extra bytes to a struct to make it fill a multiple of 4 bytes. My guess is that this is so that when you have an array of these structs each one begins on a 4 byte boundary. If you are using gcc, you can use pragmas to disable this padding as shown below.
Code:
#include <iostream>
using namespace std;
#pragma pack(push,1)
struct packed
{
int a;
short b;
};
#pragma pack(pop)
struct padded
{
int a;
short b;
};
main()
{
cout << "sizeof(packed)=" << sizeof(packed) << endl;
cout << "sizeof(padded)=" << sizeof(padded) << endl;
return 0;
}
Output:
sizeof(packed)=6
sizeof(padded)=8