From: steve AT dosius DOT zzn DOT com (Dosius) Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem using a struct Date: 8 Jan 2003 13:53:51 -0800 Organization: http://groups.google.com/ Lines: 50 Message-ID: <9307085f.0301081353.868dcfd@posting.google.com> References: NNTP-Posting-Host: 204.168.131.19 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1042062831 15907 127.0.0.1 (8 Jan 2003 21:53:51 GMT) X-Complaints-To: groups-abuse AT google DOT com NNTP-Posting-Date: 8 Jan 2003 21:53:51 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Joel Saunders" wrote in message news:... > I made a post about this yesterday, but it never showed up, so I'll try > again, and hope it posts this time. > For a basic bmp loader I made, the struct to hold the bmp header doesn't > work. I used __attribute__((__packed__)) after each item, but it's no > good. I gave the file for the program, a C extention, instead of a cpp > extention, so I know that probably makes some difference. > Here's the header... > struct BMP_Header { > unsigned int BM __attribute__((__packed__)); > unsigned long File_Size __attribute__((__packed__)); > unsigned int R_1 __attribute__((__packed__)); // Reserved 1 > unsigned int R_2 __attribute__((__packed__)); // Reserved 2 > unsigned long BMP_Offset __attribute__((__packed__)); > unsigned long Header_Info __attribute__((__packed__)); > unsigned long BMP_Width __attribute__((__packed__)); > unsigned long BMP_Height __attribute__((__packed__)); > unsigned int BMP_Planes __attribute__((__packed__)); > unsigned int BPP __attribute__((__packed__)); > unsigned long Compression __attribute__((__packed__)); > unsigned long BMP_Size __attribute__((__packed__)); > unsigned long Width_PPM __attribute__((__packed__)); > unsigned long Height_PPM __attribute__((__packed__)); > unsigned long Num_of_Colors __attribute__((__packed__)); > unsigned long Important_Colors __attribute__((__packed__)); > }image; > Here's what I had to use instead of the header: > unsigned char image[54]; > #define image_BM ((int *)&image[0])[0] > #define image_File_Size ((long *)&image[2])[0] > #define image_R_1 ((int *)&image[6])[0] > #define image_R_2 ((int *)&image[8])[0] > #define image_BMP_Offset ((long *)&image[10])[0] > #define image_Header_Info ((long *)&image[14])[0] > #define image_BMP_Width ((long *)&image[18])[0] > #define image_BMP_Height ((long *)&image[22])[0] > #define image_BMP_Planes ((int *)&image[26])[0] > #define image_BPP ((int *)&image[28])[0] > #define image_Compression ((long *)&image[30])[0] > #define image_BMP_Size ((long *)&image[34])[0] > #define image_Width_PPM ((long *)&image[38])[0] > #define image_Height_PPM ((long *)&image[42])[0] > #define image_Num_of_Colors ((long *)&image[46])[0] > #define image_Important_Colors ((long *)&image[50])[0] > What can I do to make the struct work? All help is appreciated. > Thanks. An "int" in djgpp is the same as a "long". Try "short int" instead. -uso.