sizeof(struct) returns unexpected value

It’s padding the struct to fit an 8-byte boundary. So it actually is taking 40 bytes in memory – sizeof is returning the correct value.

If you want it to only take 33 bytes then specify the packed attribute:

struct region
{
public:
    long long int x;
    long long int y;
    long long int width;
    long long int height;
    unsigned char scale;
} __attribute__ ((packed));

Leave a Comment