From: Paul Shirley Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem with Packed structs Date: Fri, 11 Apr 1997 19:06:34 +0100 Organization: wot? me? Lines: 27 Distribution: world Message-ID: References: <19970407 DOT 211716 DOT 7135 DOT 3 DOT fwec AT juno DOT com> Reply-To: Paul Shirley NNTP-Posting-Host: chocolat.foobar.co.uk Mime-Version: 1.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article , Eli Zaretskii writes >This is a very bad idea, IMHO. You should never share binary files >between different compilers. The precise way the compiler packs >struct members is very implementation-dependent and can change without >notice in future versions of the same compiler. So even if you find a >way to read in a file that was written by another compiler, your >program will break if, for example, GCC will align the structs >differently in some future version, e.g., to make its support for >Pentium Pro better. > >I would suggest to write the struct members one by one as text. The >other program will then have to read them in member by member also. >This is a bit harder to program, but a lot more robust. I think you're going a little too far here! Reading and writing binary values is faster and uses less space. It also avoids the problems that can happen with using files in text mode (I learnt long ago not to open *any* files in text mode, I like fseek to work on any compiler for instance!) It is vitally important to read and write fields explicitly, and *never* load images into anything larger than a character (to avoid endian problems) --- Paul Shirley: shuffle chocolat before foobar for my real email address