Xref: news2.mv.net comp.os.msdos.djgpp:3657 From: Shawn Hargreaves 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: NNTP-Posting-Host: tower.york.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: 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/ */