RE: [Dev-C++] [Dev-C++]: Errors in structures
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Lover of C++ <lo...@gl...> - 2001-07-03 06:07:55
|
It is not a bug, it is compiler feature. For some optimizations some c++
compilers adjust the size of structue to the multiple of 8.
Hi there
-------------
I am sorry to say that I dont have an answer for you . The LibC help file
does say that the Data Types can vary from Compiler
to Compiler But I WOULD like to show what I have also picked up with your
Code
//Snippet - START
#include <iostream.h>
#include <stdlib.h>
#include <limits.h>
struct tea_hdr{
int version; //-- 1
char jte[3]; // -- 2
//char fname_sz; // -- 3
//char infile_size; // -- 4
// char infile_crc; // -- 5
}header;
int main()
{
cout<<"Char Minimum : "<<CHAR_MIN<<endl;
cout<<"Char Max : "<<CHAR_MAX<<endl;
cout<<"Unsigned Char Max : "<<UCHAR_MAX<<endl;
cout <<"Header : "<<sizeof(header)<<endl;
cout<<"Struct : "<<sizeof(tea_hdr)<<endl;
system("PAUSE");
return 0;
}
//Snippet END
Now if you compile it as follow the Size of the Structure is 8 (The integer
(5) and the char[3]) That is ok.,
Now remove the comment before item 3 and compile and run Again.. The size
is STILL the same ?? Is this just my
PC.. must I reboot.. BUT there is more.
Now uncomment item 4 .. Compile and RUN.. SIZE is 12 that is 4 bytes
extra,But there is still more
Now uncomment item 5 and compile and run.. IT stays at 12 bytes again..
This seems to be variable
items count related. I have sifted the vars around and nothing is with
there posisions..
Also it only starts when MIXING variables in the structure.. I have a
feeling that this is something
that can be compiler related.. BUT what I did notice in the 'stddef.h' File
is that the MingW32 oaks have
a prob with the defs of the Gcc compiler and has added some macro to fix it
.. I wonder if maybe something else
also was missed that can relate to this. That the problem can maybe be at
the MingW32 project.
I don't have any answer's just maybes. but maybe it can help you in getting
to a answer For IF I cam correct you are trying to
read the information into the structure from a File .. like the header of a
MP3..
I dont have any other Ideas atound this but I hope you get a solution
Good luck
Johannes
At 09:22 03/07/2001 +0530, you wrote:
>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
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|