sizeof(struct) returns unexpected value
问题 This should be simple but I have no clue where to look for the issue: I have a struct: struct region { public: long long int x; long long int y; long long int width; long long int height; unsigned char scale; }; When I do sizeof(region) it gives me 40 when I am expecting 33 . Any ideas? (mingw gcc, win x64 os) 回答1: 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