sizeof()
-
I have problem with sizeof() function in my VC++ 6.0 compiled project struct A { short b; char c; }a; int t = sizeof(a); gives me t=4; ---------------------------------------- I think it have to be 3 struct A { char c; }a; int t = sizeof(a); gives me t=1; all right struct A { short b; }a; int t = sizeof(a); gives me t=2; all right I think that I have some problem with my project settings but I do not what. In some other projct the sizeof() works in way a want it gives 3 for the structure above. Can someoen explan the reason of the sizeof() function behavier. Thank you in advance, Seval YILMAZ
-
I have problem with sizeof() function in my VC++ 6.0 compiled project struct A { short b; char c; }a; int t = sizeof(a); gives me t=4; ---------------------------------------- I think it have to be 3 struct A { char c; }a; int t = sizeof(a); gives me t=1; all right struct A { short b; }a; int t = sizeof(a); gives me t=2; all right I think that I have some problem with my project settings but I do not what. In some other projct the sizeof() works in way a want it gives 3 for the structure above. Can someoen explan the reason of the sizeof() function behavier. Thank you in advance, Seval YILMAZ
struct elements are aligned to boundaries (particularly word boundaries) to improve performance. Use
#pragma pack(push,1)
and#pragma pack(pop)
to align a struct on byte boundaries:#pragma pack(push,1)
struct A
{
short b;
char c;
}a;
#pragma pack(pop)- Mike