Why GCC do this???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

I'm writing a chunk of software that must read a
bitmap file.
The first field of bitmap header is the ID ( 16 bit ),
and then the size of file ( 32 bit ).
( after these , thre is a reserved field ( 32 bit ))

In example.

42 4d c6 4a 43 00 00 00 00 00

ID is   42 4d   ,  that is BM
Size is   00 43 4a c6, that is 4410045 ( 4.4 mb)
Reserved is 00 00 00 00 ...... nothing.

I have defined this structure.

typedef unsigned short word;
typedef unsigned long dword;

typdef struct BMP_H {
   word ID;
   dword size;
   dword res;
} BMP_H; //this structure is 10 byte

then...

fread( (void *)&my, 12 ,1,file );

..don't read the header correct.
It read

Id: BM ( correct )
size: 67 ( no )
res: 3538944 ( no )

Looking at file above, I understand that gcc read 4
byte for Id, in fact 67 ( in hex is 43 )....

WHY?????????
Why it read 4 byte instead of 2???

In addition sizeof return me 12 instead of 10.

but, in this way...

fread( (void *)&my.ID, 2 ,1,file );
fread( (void *)&my.size, 10 -2, 1, file);

..the result is correct....

why with the first way don't run correctly??

( i've tried with  old TURBO C for msdos, and the
resulty is correct in either ways..)

Who explane me this, please???


	

	
		
____________________________________________________________
Yahoo! Companion - Scarica gratis la toolbar di Ricerca di Yahoo! 
http://companion.yahoo.it

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux