delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/07/29/21:27:31

Subject: Re: Fread
To: enrico AT max DOT tiac DOT net (Cuthalion / Sliced Bread)
Date: Fri, 29 Jul 1994 17:47:03 -0600 (CDT)
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
From: mcastle AT umr DOT edu (Mike Castle)

Amazingly enough Cuthalion / Sliced Bread said:
> 
> Allright.  It seems that GCC pads it's structs with extra bytes in order to get proper alignment of it's long words.  This is all very fine and good, until I want to go and fread a structure written by a programme compiled with some other compiler.  Any s> uggestions?
> 

hurm.... occasional carriage return would have been nice.... fix
your editor


in short, this is very non portable and generally a bad thing to
do.  If you must use binary file format, then strictly define a
file format and read it one byte at a time (well, analyze it one
byte of a time, still use fread to read in big chunks).

Other than that, try #pragma pack (though generally using
#pragmas are a bad idea because the same pragma can mean
different things on different machines.

Even then, you still have to worry bout sizeof(int) problems (16,
32 or 64 bit) and so on.

mrc

-- 
Mike Castle .-=NEXUS=-.  Life is like a clock:  You can work constantly
  mcastle AT cs DOT umr DOT edu     and be right all the time, or not work at all
   mcastle AT umr DOT edu       and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen

- Raw text -


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