[SDL] endianity

Mattias Engdegård f91-men at nada.kth.se
Thu Jun 21 02:38:31 PDT 2001


Listen people, we've had the discussion about floats in files and network
protocols before on this list so I suggest you read the archives

To summarise:
If you want to transmit floats (via files or networks), keep in mind that

a) the byte-orders differ
b) the formats differ --- this is *mostly* a historical thing since most modern
   machines use IEEE-754 formats but there's no guarantee that some exotic
   device will surface again, most likely where you least expect it
c) the semantics differ

For practical purposes, c) is the biggie here. Once you've transmitted a
bunch of numbers, you want them to be interpreted the same way and operations
done on them to give the same results, and IEEE-[78]54 nonwithstanding,
there's no guarantee for this. (Sometimes you can even get different results
when running the same binary on the same architecture - think FSIN on
an AMD vs an Intel x86)

So, lessons:

1) Unless you *know* what you are doing, don't transmit/store floats to other
   platforms. Use integers (fixnums if you need)
2) also unless you know what you are doing, store/transmit floats in ASCII
   (text file formats are usually a good idea anyway)




More information about the SDL mailing list