Bugfix: Compiler optimisations on certain compilers could cause the
networked version to fail (indication: warning message "warning: dereferencing type-punned pointer will break strict-aliasing rules"). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2266 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
5f6b27bb80
commit
1ee4c7976a
@ -143,6 +143,19 @@ short Message::getShort()
|
||||
return ntohs(*(short*)(&m_data[m_pos-sizeof(short)]));
|
||||
} // getShort
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Adds a floating point value to the message.
|
||||
* \param data Floating point value to add.
|
||||
*/
|
||||
void Message::addFloat(const float data)
|
||||
{
|
||||
// The simple approach of using addInt(*(int*)&data)
|
||||
// does not work (at least with optimisation on certain g++ versions,
|
||||
// see getFloat for more details)
|
||||
int n;
|
||||
memcpy(&n, &data, sizeof(float));
|
||||
addInt(n);
|
||||
} // addFloat
|
||||
// ----------------------------------------------------------------------------
|
||||
float Message::getFloat()
|
||||
{
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
void addString(const std::string &data);
|
||||
void addStringVector(const std::vector<std::string>& vs);
|
||||
void addUInt(unsigned int data) { addInt(*(int*)&data); }
|
||||
void addFloat(float data) { addInt(*(int*)&data); }
|
||||
void addFloat(const float data);
|
||||
void addBool(bool data) { addChar(data?1:0); }
|
||||
void addChar(char data) { addCharArray((char*)&data,1);}
|
||||
void addCharArray(char *c, unsigned int n=1)
|
||||
|
Loading…
Reference in New Issue
Block a user