|
From: Abhijit S. <mu...@gm...> - 2002-06-11 15:37:00
|
AFAIK, GCC (and derivatives) don't store structures linearly, they pad the elements for optimization reasons. So if you want to read in stuff, you'll have to read them in separately. I think there's a command-line option somewhere to disable this behaviour... Over to you, <put_your_name_here>. -------------------------- http://mudeth.tripod.com ----- Original Message ----- From: "balamurali muraleedharan" <bal...@re...> To: <dev...@li...> Sent: Tuesday, June 11, 2002 7:25 PM Subject: [Dev-C++] doubt > int main() > { > bitmapfileheader bmpf; > cout<<sizeof(bmpf); > } > here the result shows the size as 16bytes instead of 14bytes > also while reading into this structure using file.open and > file.read statement always wrong data is contained in the > structure where the read data is stored.Why is this so? > There is error only while reading into the structure as a whole as > in the case > file.open("file.bmp",ios::binary|ios::in); > file.read((char*)&bmpf,sizeof(bmpf)); > This always reads erroneous values into the corresponding elements > in the structure.But > file.open("file.bmp",ios::binary|ios::in); > file.read((char*)&bmpf.signature,sizeof(bmpf.signature)); > file.read((char*)&bmpf.filesize,sizeof(bmpf.filesize)); > file.read((char*)&bmpf.reserved,sizeof(bmpf.reserved)); > file.read((char*)&bmpf.dataoffset,sizeof(bmpf.dataoffset); > this reads the correct values into the respective elements of the > structure. > why is this so? > why cant we simply read the contents of the file into the > structure using the first statement?what really happens during > this process? > I am using G++ in Linux environment. > Please help me. |