The only thing that I was able to figure out from that program is how good
the implementation is at memory management. There are no "gaps"
when each of int*, char*, and void* are declared in that particular order.
But here's a case where you can introduce holes:
Code:
#include <iostream>
using namespace std;
int main() {
struct CS {
const wchar_t szOffsetCS[80 + 1];
void* pvCS;
int* piCS;
char* pcCS;
};
CS cs = {
L"The quick brown fox jumped over the lazy dog!",
0,
0,
0
};
cout << "Size of `cs' "
<< ( sizeof(cs) == sizeof(cs.szOffsetCS)
+sizeof(cs.pvCS)
+sizeof(cs.piCS)
+sizeof(cs.pcCS) ? "== " : "!= " )
<< "sum of sizes of its contents."
<< '\n';
}
Output:
Code:
Size of `cs' == sum of sizes of its contents.
Code:
#include <iostream>
using namespace std;
int main() {
struct CS {
const char szOffsetCS[80 + 1];
void* pvCS;
int* piCS;
char* pcCS;
};
CS cs = {
"The quick brown fox jumped over the lazy dog!", // not wide string now
0,
0,
0
};
cout << "Size of `cs' "
<< ( sizeof(cs) == sizeof(cs.szOffsetCS)
+sizeof(cs.pvCS)
+sizeof(cs.piCS)
+sizeof(cs.pcCS) ? "== " : "!= " )
<< "sum of sizes of its contents."
<< '\n';
}
Output:
Code:
Size of `cs' != sum of sizes of its contents.
I'm not sure if this tells you anything about word boundaries, though.