Message-Id: <3.0.6.32.19990303124259.0094a760@pop.globalserve.net> X-Sender: derbyshire AT pop DOT globalserve DOT net (Unverified) X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32) Date: Wed, 03 Mar 1999 12:42:59 -0500 To: djgpp AT delorie DOT com From: Paul Derbyshire Subject: Re: Real stupid problem. In-Reply-To: <36db1881.8437368@news.tudelft.nl> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Reply-To: djgpp AT delorie DOT com At 11:21 PM 3/1/99 GMT, you wrote: >struct SXM_Pat_header{ > int pat_size; > char pack_type; > short nr_rows; > short pattern_data_size; >}; > >struct SXM_Pat_header{ > char pat_size[4]; > char pack_type; > char nr_rows[2]; > char pattern_data_size[2]; >}; > >These are two structures, and They should be the same size at least I >think they should be. But DJGPP manages to call the first one a size >of 12, and the second one (the correct size) 9. > > Does anyone know why? And if so, how do I fix it? It's padding the structs. The latter struct is all chars, but the former has shorts at the end that it aligns to word boundaries. You end up with: Offset Struct 1 Struct 2 0 int pat_size char pat_size[4] 1 | | 2 | | 3 V V 4 char pack_type char pack_type 5 packing byte char nr_rows[2] 6 packing byte V 7 packing byte char pattern_data_size[2] 8 short nr_rows ____V____________________ 9 V 10 short pattern_data_size 11 ____V__________________ (length 12) (length 9) To get these structs compatible, pack the first one: struct SXM_Pat_header { int pat_size __attribute__ ((__packed__)); char pack_type __attribute__ ((__packed__)); short nr_rows __attribute__ ((__packed__)); short pattern_data_size __attribute__ ((__packed__)); }; -- .*. "Clouds are not spheres, mountains are not cones, coastlines are not -() < circles, and bark is not smooth, nor does lightning travel in a `*' straight line." ------------------------------------------------- -- B. Mandelbrot |http://surf.to/pgd.net _____________________ ____|________ Paul Derbyshire pderbysh AT usa DOT net Programmer & Humanist|ICQ: 10423848|