[SDL] Endian Conversion?

Neil Bradley nb at synthcom.com
Mon Jan 6 10:59:01 PST 2003

> It runs fine on x86 machines (Windows and Linux). However, I'd like to be
> able to get the same file to run on other systems, like PPC. Basically the
> only thing it trips up on is the reading of the binary integer,
> fread(&packFSize, sizeof(int), 1, pak);
> That's the line used to read the integer. So all I'd like to know is, is
> there anyway I can make use of the SDL_BYTEORDER to convert the binary
> integer?

No. You're better off doing this:

	int packFSize;

	packFSize = fgetc(pak);
	packFSize = ((int) fgetc(pak)) << 8;
	packFSize = ((int) fgetc(pak)) << 16;
	packFSize = ((int) fgetc(pak)) << 24;

(it'd be a good idea to check for end of file of course, but you can
figure that out)

No #ifdefs or anything funky required and it works on all platforms.


Neil Bradley            In the land of the blind, the one eyed man is not
Synthcom Systems, Inc.  king - he's a prisoner.
ICQ #29402898

More information about the SDL mailing list