Xref: news2.mv.net comp.os.msdos.djgpp:3655 From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Structure size Date: Thu, 09 May 1996 18:28:34 -0700 Organization: Alcyone Systems Lines: 29 Message-ID: <31929BC2.424711F9@alcyone.com> References: <3190895C DOT 41C6 AT tc0 DOT chem DOT tue DOT nl> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Gert-Jan Schoenmakers wrote: > I've recently switch from Microsoft C/C++ 7.0 to djgpp 2.0 for > developping signal processing software. Now I have a trouble reading > binary data files which consist of a header and an amount of data. The > recent discussion about the sizeof(int) was a first step in solving the > problems I had (I redifined the int's to short int's) but now I'm stuck. > The MSC compiled program tells me sizeof(struct header)=98 and the DJGPP > compiled program tells me sizeof(struct header)=100.... Can someone help > me out on this one ???? It's because ANSI C gives no specification on what kind of padding members of structures will be given. That is to say, what you are attempting to do is inherently nonportable. You should be reading in the members one at a time. However, there are attributes to allow you to do this in gcc; there's a bug in g++ 2.7.2 that won't even let this work; you'll need to use a #pragma. Check the info file on gcc. If you want your code to be at all portable (which it sounds like might not be a bad idea, considering you're moving over from Microsoft to DJGPP), I recommend against this method; read in the members one at a time. -- Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_