I am cleaning up some of our network-code and while replacing various integer types (int
, unsigned short
, ...) with more explcit typedefs such as int32_t
and uint16_t
I was wondering how portable double
and float
are between different compilers. We are sending structures similar to the following:
struct foo
{
uint32_t id;
double dbl;
};
...
// copy_packed() copies packed bytes of integral type and adheres
// to network byte-ordering
copy_packed(int32_t data, char* buffer, char* end);
copy_packed(uint32_t data, char* buffer, char* end);
copy_packed(uint16_t data, char* buffer, char* end);
...
// overload for structure types calls overloads for its members
void copy_packed(foo &data, char* buffer, char* end)
{
copy_packed(data.id, buffer);
copy_packed(data.id, buffer);
};
Until now only programs compiled with VC++ are used, but use of the protocol on GCC is scheduled.
The question is now: can double
amd float
be safely send over the wire even when then interpreted by different compilers? The question - as far as I understand - boils down to whether GCC and VC++ comply to IEEE754. Or maybe provide functions to convert to conformant packaging?
Any hints on the matter?