i think that it aligns to sizeof int, since the cpu works with ints best.
are u sure that 20 isnt a typo ? it should be 16, i think, since ints are 4 bytes long.
actually, i just tried it in mvc++, and its 16: what compiler are u using?
this is probably over cryptic. but anyway,
#include <iostream>using namespace std;const max = 10; struct S{ char c[max]; int i;};void main(void){ cout << sizeof(S) << endl; S s; for(int i = 0; i <max; i++) s.c[i] = i; s.i = 15; char* ptr = (char*)&s cout << (__int8)ptr[max - 1] << endl; cout << *(int*)(&ptr[max] + sizeof(char) * ( 4 - max % 4)); cout << endl; cout << (char*)&s.c - (char*)&s.i}
i woiuldnt count on a compiler organizing the data to literally represent a struct, even though in this example, the pads are addes to before the int.
im pretty sure there is a way to turn off padding...
Edited by - evilcrap on February 6, 2002 11:03:47 PM