I am running into a couple of errors related to "htonf" c++ function error while compiling my code. Help will be much appreciated.
Following are the errors:
Error C2556 'long htonf(float)': overloaded function differs only by return type from 'unsigned int htonf(float)'
Error C2371 'htonf': redefinition; different basic types ecueHost
Error C2065 'htonf': undeclared identifier
The error is appearing in the datapacket.cpp below
#include "str.h"
#include "DataPacket.h"
#include "exception.h"
#include "message.h"
#include "object.h"
#include "util.h"
#define MAX_DATA_LENGTH 4096
long htonf(float f)
{
long x;
x = *((long*)&f);
x = htonl(x);
return x;
}
float ntohf(long l)
{
float f;
l = ntohl(l);
f = *((float*)&l);
return f;
}
In the "winsock2.h" header file included in "datapacket.h" header, the "htonf" is defined as under:
#ifndef htonf
__inline unsigned __int32 htonf ( float Value )
{
unsigned __int32 Tempval;
unsigned __int32 Retval;
Tempval = *(unsigned __int32*)(&Value);
Retval = _WS2_32_WINSOCK_SWAP_LONG
(Tempval);
return Retval;
}
#endif /* htonf */
and in the "datapacket.cpp" file itself the "htonf" is also declared here
// Store a float to the datapacket
TDataPacket& TDataPacket::operator<<(float f)
{
long x = htonf(f);
return SerializingIn(&x, LONG_SIZE);
}