delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/10/01:33:05

Xref: news2.mv.net comp.os.msdos.djgpp:3657
From: Shawn Hargreaves <slh100 AT york DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: i/o file handling - intege
Date: Thu, 9 May 1996 23:06:31 +0100
Organization: The University of York, UK
Lines: 32
Message-ID: <Pine.SGI.3.91.960509230139.22134A@tower.york.ac.uk>
NNTP-Posting-Host: tower.york.ac.uk
Mime-Version: 1.0
In-Reply-To: <Pine.SUN.3.91.960509174409.20870A-100000@is>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Thu, 9 May 1996, Eli Zaretskii wrote:

> This thread is going on for so long, that another bit of info, however 
> insignificant, won't hurt anybody.  So here goes: did you know there are 

Good point. So I may as well join in as well :-)

> functions specifically designed to read and write 32-bit words?  Well, 
> there are, they are called `getw' and `putw'.  Look them up in the libc 
> Info reference.  Warning: they are neither ANSI nor POSIX, so don't use 
> them in a program that should be portable.

If you are interested in portability, it is worth considering the 
implications of endianess. Even if you don't care about portability it 
can't hurt to be aware of the issue: you might not be planning it now, 
but who knows if in a couple of years you may want to port your code to 
the Mac or a Sun or something...

The best way I've found to deal with this is to define two versions of 
getw and putw, one for each endianness. You call whichever one your file 
format is using, making sure always to read 16 and 32 bit variables with 
these functions and not with an fread of the whole structure (this avoids 
structure alignment problems), and then your code can be made to work with 
either endianness simply by changing these functions...


/*
 *	Shawn Hargreaves.        Why is 'phonetic' spelt with a ph?
 *	Check out Allegro and FED on http://www.york.ac.uk/~slh100/
 */


- Raw text -


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