[Gllug] endian.h
Tethys
tet at accucard.com
Wed Feb 5 16:51:46 UTC 2003
rich at annexia.org writes:
>> >So betoh32 <-> ntohl && letoh32 <-> htonl
>
> [...]
>
>Hmmm ... except that it probably won't fail. On, say, Sparc machines,
>the betoh32 (Big Endian to Host) transformation _is_ a null transformation,
>because Sparcs are already Big Endian.
Yes, it will still fail. In fact, if you do a direct swap as described,
it'll even fail on little endian, too!
On little endian:
betoh32 -> ntohl -> transform (correct)
letoh32 -> htonl -> transform (*WRONG*)
On big endian:
betoh32 -> ntohl -> no transform (correct)
letoh32 -> htonl -> no transform (*WRONG*)
On little endian, you can fix that with "#define letoh32(x) (x)".
The same trick doesn't work on big endian, though, and you need
to resort to a manual conversion. With glibc, you can use bswap_32(),
but it's not portable.
Tet
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list