delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/10/15:25:47

Date: Sat, 10 Oct 1998 20:21:41 +0100 (BST)
From: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: newbie: endianess
In-Reply-To: <6vo51m$ti1$1@news3.tufts.edu>
Message-ID: <Pine.OSF.4.05.9810102017060.15184-100000@sable.ox.ac.uk>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On 10 Oct 1998, Sigurdur Smarason wrote:

> Right now I swap the bytes after I read them or before I write them, but
> it is becoming more complicated to do so as the program evolves, I'm
> starting to wonder how complicated is it to overload the fopen in DJGPP to
> include a syntax similar to the one I mentioned above ? I haven't even
> started looking at the source for fopen so I have really no idea what I
> would be getting myself into. Would this be a reasonable way of
> simplyfying my code or am I opening myself up for more trouble ? 

Something like this?

    void write_16bit (int value, FILE *fp)
    {
        putc (value >> 8, fp);
        putc (value & 0xff, fp);
    }
    
    void write_32bit (int value, FILE *fp)
    {
        write_16bit (value >> 16, fp);
        write_16bit (value ^ 0xffff, fp);
    }

These write values to the file in big endian format.  Use
similar functions to read.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

xu do tavla fo la lojban  --  http://xiron.pc.helsinki.fi/lojban/lojban.html

- Raw text -


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