X-Trace-PostClient-IP: 68.147.131.211 From: Brian Inglis Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem using a struct Organization: Systematic Software Message-ID: References: X-Newsreader: Forte Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 65 Date: Thu, 09 Jan 2003 11:28:37 GMT NNTP-Posting-Host: 24.71.223.147 X-Complaints-To: abuse AT shaw DOT ca X-Trace: news1.calgary.shaw.ca 1042111717 24.71.223.147 (Thu, 09 Jan 2003 04:28:37 MST) NNTP-Posting-Date: Thu, 09 Jan 2003 04:28:37 MST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Wed, 8 Jan 2003 15:58:30 +0000 (UTC), "Joel Saunders" wrote: >I made a post about this yesterday, but it never showed up, so I'll try >again, and hope it posts this time. usenet posts take time to propagate around the world and replies take time to propagate back to you -- especially if you have a cheap ISP -- you may not even get to see all of your replies -- be patient -- check to see if google shows you have any replies -- you already had two replies that I can see before you reposted >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? use short instead of int for now, until you can use int16_t (C99) Thanks. Take care, Brian Inglis Calgary, Alberta, Canada -- Brian DOT Inglis AT CSi DOT com (Brian dot Inglis at SystematicSw dot ab dot ca) fake address use address above to reply abuse AT aol DOT com tosspam AT aol DOT com abuse AT att DOT com abuse AT earthlink DOT com abuse AT hotmail DOT com abuse AT mci DOT com abuse AT msn DOT com abuse AT sprint DOT com abuse AT yahoo DOT com abuse AT cadvision DOT com abuse AT shaw DOT ca abuse AT telus DOT com abuse AT ibsystems DOT com uce AT ftc DOT gov spam traps