RE: [Dev-C++] [Dev-C++]: Errors in structures
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2001-07-03 11:29:09
|
This is not an error. A structure's space in memory is not the summary
of the sizeof() of everyone of its members. It may occupy more memory
due to compiler's memory management technique. For more information read
section 8.7 in K&R 2. For example a compiler's memory management can be
a connected list of structs (compilers, operating systems e.t.c. are
written in C/C++ too). So in the example of K&R it has a list of unions
connected structs:
typedef long Align;
union header
{
struct
{
union header *ptr; /* points to next block */
unsigned size;
}s;
Align x;
};
typedef union header Header;
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Jeethu
Rao
Sent: Tuesday, July 03, 2001 5:52 AM
To: Dev CPP Mailing List
Subject: [Dev-C++] [Dev-C++]: Errors in structures
Hi,
I've noticed this strange little Bug.I'm not certain weather its a bug
or a feature.
The size of this structure is actually 13 bytes.
But sizeof(header) says its 16.
struct tea_hdr
{
char jte[3];
unsigned char version;
DWORD infile_size;
DWORD infile_crc;
unsigned char fname_sz;
}header;
No, if I comment out the fname_sz member,
struct tea_hdr
{
char jte[3];
unsigned char version;
DWORD infile_size;
DWORD infile_crc;
//unsigned char fname_sz;
}header;
sizeof(header) returns 12.
Is the compiler trying to align structure on DWORD boundaries?
How do I get rid of this Bug/Feature ?
Thnx,
Jeethu Rao
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|