Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Strange bug in transmission of float values over TCP/IP

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Strange bug in transmission of float values over TCP/IP
bamccaig
Member #7,536
July 2006
avatar

Billybob
Member #3,136
January 2003

What about Mac's!? ... oh wait.

The machines we use in day to day life are no longer x86 only. Look at your phone. ARM is becoming an increasing popular platform, and it can run in either endianness. Depending on the application it may be wise to be endian-neutral in your network code just so you have ability to interface with mobile devices.

That said, if your networking API is designed well, you can skip endian-neutrality for now and add it later with minimal effort.

ImLeftFooted
Member #3,935
October 2003
avatar

Wait ARM can be big endian? My code has been assuming little endian without issues.

What causes ARM to switch -- are there any iPhone that would have it switched?

BAF
Member #2,981
December 2002
avatar

axilmar said:

Both ntohf and htonf do the exact same job: they reverse the bytes of the variable.

Must be something about C coders. You have absolutely no good reason to not use both functions. Doing it the way you've done it only adds confusion and makes the code harder to read.

I like my code to be self documenting, not as archaic and obscure as possible.

Billybob
Member #3,136
January 2003

Wait ARM can be big endian?

According to WikiPedia's article on Bi-endian Hardware, yes. It can be either changed by software, or on some platforms, locked by the hardware. I would bet Apple's A4, and any other uses of ARM, are hardware locked.

axilmar
Member #1,204
April 2001

BAF said:

Must be something about C coders. You have absolutely no good reason to not use both functions. Doing it the way you've done it only adds confusion and makes the code harder to read.

I like my code to be self documenting, not as archaic and obscure as possible.

I agree, I only did this in the context of the example. In the real code at work, I have two functions (ntohf, htonf), which is helpful: if you want to check incoming values, you can put a breakpoint to 'ntohf', for example.

 1   2   3 


Go to: