public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Reading big-endian binary data on a little-endian machine
@ 2003-08-15 19:40 Rudy Koot
  0 siblings, 0 replies; 3+ messages in thread
From: Rudy Koot @ 2003-08-15 19:40 UTC (permalink / raw)
  To: gcc-help




>From: Mark Panning <mpanning@seismo.berkeley.edu>
>Reply-To: Mark Panning <mpanning@seismo.berkeley.edu>
>To: gcc-help@gcc.gnu.org
>Subject: Reading big-endian binary data on a little-endian machine
>Date: Fri, 15 Aug 2003 12:34:23 -0700 (PDT)
>
>____________________________________________
>Did you know that you could
>earn money with Dot TK? It's
>simple. Become an affiliate
>today and promote Dot TK on
>your website!
>
>http://www.dot.tk/vc00804.html
>____________________________________________
>
>
>
>I currently am in the process of trying to move some of my codes from a
>Big-Endian Solaris system to a little-endian PC cluster running Linux.  I 
>would
>however like to continue to use the binary data files I was using on the
>Big-Endian system.
>In ifc, a Fortran compiler, there is an environment variable F_UFMTENDIAN 
>which
>can be set such that all READ operations automatically perform a 
>big-to-little
>conversion and all WRITE operations perform the little-to-big covnersion.
>Is there something similar which I can do with gcc or with options in the
>read/write or fread/fwrite functions?
>Mark Panning
>

No C is just too low-level for that, but...

If you only write an array of integers (NO floats or strings) you might get 
away with it by writing your own read and write functions that convert them 
on the fly.

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Reading big-endian binary data on a little-endian machine
  2003-08-15 19:34 Mark Panning
@ 2003-08-15 19:47 ` Eljay Love-Jensen
  0 siblings, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2003-08-15 19:47 UTC (permalink / raw)
  To: Mark Panning, gcc-help

Hi Mark,

No easy way, on this one.

If your program uses a canonical data format, and it's already taken care .

For example, writing a 16-bit or 32-bit number out with htons and htonl (respectively), and reading them in with ntohs and ntohl will give a consistent canonical binary format.  If your application does the same, then the binary format shouldn't be an issue.

Unfortunately, in my experience, many C/C++ programmers will write a structure out blindly, such as "fwrite(myStruct, sizeof myStruct, 1, fp);" which doesn't adjucate the 16-bit and 32-bit numbers into a canonical format (such as the aforementioned network byte order), and also includes any padding bytes which will often vary from platform to platform.  A "platform" being both the OS and the compiler, in this case.

Serializing output and marshalling input are important, yet often overlooked issue.

Sincerely,
--Eljay


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Reading big-endian binary data on a little-endian machine
@ 2003-08-15 19:34 Mark Panning
  2003-08-15 19:47 ` Eljay Love-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Panning @ 2003-08-15 19:34 UTC (permalink / raw)
  To: gcc-help

I currently am in the process of trying to move some of my codes from a 
Big-Endian Solaris system to a little-endian PC cluster running Linux.  I would 
however like to continue to use the binary data files I was using on the 
Big-Endian system. 
In ifc, a Fortran compiler, there is an environment variable F_UFMTENDIAN which 
can be set such that all READ operations automatically perform a big-to-little 
conversion and all WRITE operations perform the little-to-big covnersion.
Is there something similar which I can do with gcc or with options in the 
read/write or fread/fwrite functions?
Mark Panning

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-08-15 19:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-15 19:40 Reading big-endian binary data on a little-endian machine Rudy Koot
  -- strict thread matches above, loose matches on Subject: below --
2003-08-15 19:34 Mark Panning
2003-08-15 19:47 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).