OffsetOf getting wrong value

struct SSomeData {
char mcChar;
double mdDouble;
bool mbBool;


};

int main() {
using namespace std;


cout << "Offset of mbBool = " << offsetof(SSomeData, mbBool) << endl;
return 0;
}

This code returns 16. But if I try to add double and char that should be 9. I don't get it. Why am I getting 16? size of double is 8 and size of char is 1. Where does 16 come from?
Last edited on
OffsetOf getting wrong value

Any time you find yourself saying something like this, you should rethink it. It obviously doesn't return the wrong value. It just returns a value that you didn't expect.

Your structure will be padded on most implementations.

See: http://www.drdobbs.com/cpp/padding-and-rearranging-structure-member/240007649

Topic archived. No new replies allowed.