www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/12/19:26:40

From: Paul Shirley <Paul AT foobar DOT co DOT uk DOT chocolat>
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: <dVHy2DAq2nTzEweF@foobar.co.uk>
References: <19970407 DOT 211716 DOT 7135 DOT 3 DOT fwec AT juno DOT com>
<Pine DOT SUN DOT 3 DOT 91 DOT 970408141204 DOT 1046S-100000 AT is>
Reply-To: Paul Shirley <junk AT defeating DOT email DOT address>
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 <Pine DOT SUN DOT 3 DOT 91 DOT 970408141204 DOT 1046S-100000 AT is>, Eli Zaretskii
<eliz AT is DOT elta DOT co DOT il> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019