From: eplmst AT lu DOT erisoft DOT se (Martin Stromberg) Newsgroups: comp.os.msdos.djgpp Subject: Re: struct problem Date: 8 Jan 2003 11:03:14 GMT Organization: Ericsson Erisoft AB, Sweden Lines: 64 Message-ID: References: <4beb6242eec71f0c5cf10defc2e78b1d DOT 62691 AT mygate DOT mailgate DOT org> NNTP-Posting-Host: lws256.lu.erisoft.se X-Newsreader: TIN [version 1.2 PL2] To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Joel Saunders (jbs30000 AT aol DOT com) wrote: : In writting a simple bmp loader, I'm having problems with the struct for : the bmp header. Even with __attribute__((__packed__)) after each item: : struct BMP_Header { : unsigned int BM __attribute__((__packed__)); 4 bytes. : unsigned long File_Size __attribute__((__packed__)); 4 bytes. : unsigned int R_1 __attribute__((__packed__)); // Reserved 1 4 bytes. : unsigned int R_2 __attribute__((__packed__)); // Reserved 2 4 bytes. : unsigned long BMP_Offset __attribute__((__packed__)); 4 bytes. ... : }image; : I had to do this to use the header information: : unsigned char image[54]; : #define image_BM ((int *)&image[0])[0] 2 bytes. : #define image_File_Size ((long *)&image[2])[0] 4 bytes. : #define image_R_1 ((int *)&image[6])[0] 2 bytes. : #define image_R_2 ((int *)&image[8])[0] 2 bytes. : #define image_BMP_Offset ((long *)&image[10])[0] 4 bytes. : #define image_Header_Info ((long *)&image[14])[0] Perhaps you see the problem now? You forgot to check what sizeof(int) equals. Then a question of my own; is there any advantage using "((long *)&image[2])[0]" vs. "*((long *)&image[2])"? Right, MartinS