Packing/unpacking binary data in C - doubles, 64 bits
Kevin D. Clark
kevin_d_clark at comcast.net
Thu Sep 10 10:12:12 EDT 2009
Bruce Labitt writes:
> Kevin D. Clark wrote:
> > 2: Typically, binary stuff is sent over the network in "network byte
> > order" and network byte order is big-endian. This statement is not
> > universally agreed to -- in fact I used to work at a shop where they'd
> > never even considered this problem and it turned out that they were
> > sending (most) stuff over the wire in little-endian format.
> >
> >
> That only works if both ends are the same - definitely not portable. In
> my case, the client is little-endian and the server is big-endian.
No, that always works and it is definitely portable. Read what I said
again: when you transmit binary integers onto the wire, make sure they
exist in network-byte-order.
May I politely suggest that you consult a decent computer networking
book? Please take a look at the functions htonl() and ntohl().
Question: from your various postings on this list, I gather that you
are using MPI. If this is true, why aren't you just using things like
MPI_INT, MPI_DOUBLE, and possibly MPI_LONG_LONG? Why not let your MPI
library take care of details like this for you? I guarantee you that
any decent MPI implementation is going to be well-debugged and
efficient. It should also take care of any endian issues that you
might encounter.
Regards,
--kevin
--
GnuPG ID: B280F24E God, I loved that Pontiac.
alumni.unh.edu!kdc -- Tom Waits
http://kdc-blog.blogspot.com/
More information about the gnhlug-discuss
mailing list