I am using VC 6.0
Why is it happeningCode:class C
{
char c;
int int1;
int int2;
int i;
long l;
short s;
};
The size of this class is 24 bytes
class C {
int int1;
int int2;
int i;
long l;
short s;
char c;
};
Now the size of this class is 20 bytes.
Printable View
I am using VC 6.0
Why is it happeningCode:class C
{
char c;
int int1;
int int2;
int i;
long l;
short s;
};
The size of this class is 24 bytes
class C {
int int1;
int int2;
int i;
long l;
short s;
char c;
};
Now the size of this class is 20 bytes.
The cause of this is 'structure padding'. This option can be changed at compiler options dialog window. Search the forums or google for 'structure padding' or 'srtucture alignment'
Hob
thanx i searched on the net(as you said)....and did found out the reason for it...but didn't found anything on switching off this option in VC 6.0Quote:
Originally Posted by Hobson
Go to 'Project settings..' dialog, choose 'C / C++' tab, and click on combobox where 'General' is placed. Choose 'Code generation' option in that combo, and option 'Struct member alignment' will become visible.Quote:
Originally Posted by sunnypalsingh
Same effect can be achieved with "#pragma pack' directive.
Anyway, is it necessary for you to change this setting?
Hob
No it wasn't necessary....just curious to know more about compiler settings
If u use Pragma Pack(1) it reduced to 19 only
For further details Take a LOOK at : C/C++ Language Reference PACK and /Zp compiler optionCode:#pragma pack(1)
class Cq
{
char c;
int int1;
int int2;
int i;
long l;
short s;
};
Quote:
MSDN :The default data member packing for structures and classes is 8 bytes. MFC headers change this to 4 bytes to save memory. Because afxdocob.h is missing the #pragma pack(pop), all user class declarations compiled after including this file will be packed with 4-byte alignment.
It didn't work with project..setting..etc when i changes it to 1 byte alignmentand it gave me the warning
Quote:
warning C4653: compiler option 'structure packing (/Zp)' inconsistent with precompiled header; current command-line option ignored
but it did work with the pragma option
Code:#pragma pack(1)
Maybe 'Rebuild All' would help. Give it a try.
Nice...it did workedQuote:
Originally Posted by Hobson