[SDL] Printed documentation?

Sam Lantinga slouken at devolution.com
Sun Jan 19 19:27:01 PST 2003


so that works if a file is being read on a little endian system that was
written on a big endian system?

----- Original Message -----
From: "Neil Bradley" <nb at synthcom.com>
To: <sdl at libsdl.org>
Sent: Monday, January 06, 2003 10:57 AM
Subject: Re: [SDL] Endian Conversion?


> > 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
>
> --------------------------------------------------------------------------
-----
> Neil Bradley            In the land of the blind, the one eyed man is not
> Synthcom Systems, Inc.  king - he's a prisoner.
> ICQ #29402898
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list