compile fixes for gcc 4.7 in 32bit platforms

This commit is contained in:
Eduardo Bart 2012-04-04 12:12:25 -03:00
parent 27e24bda28
commit 8b184d3ce8
3 changed files with 14 additions and 6 deletions

View File

@ -47,7 +47,7 @@ uint8 InputMessage::getU8(bool peek)
uint16 InputMessage::getU16(bool peek)
{
checkRead(2);
uint16 v = *(uint16_t*)(m_buffer + m_readPos);
uint16 v = Fw::readLE16(m_buffer + m_readPos);
if(!peek)
m_readPos += 2;
@ -58,7 +58,7 @@ uint16 InputMessage::getU16(bool peek)
uint32 InputMessage::getU32(bool peek)
{
checkRead(4);
uint32 v = *(uint32*)(m_buffer + m_readPos);
uint32 v = Fw::readLE32(m_buffer + m_readPos);
if(!peek)
m_readPos += 4;
@ -69,7 +69,7 @@ uint32 InputMessage::getU32(bool peek)
uint64 InputMessage::getU64(bool peek)
{
checkRead(8);
uint64 v = *(uint64*)(m_buffer + m_readPos);
uint64 v = Fw::readLE64(m_buffer + m_readPos);
if(!peek)
m_readPos += 8;

View File

@ -44,7 +44,7 @@ void OutputMessage::addU8(uint8 value)
void OutputMessage::addU16(uint16 value)
{
checkWrite(2);
*(uint16_t*)(m_buffer + m_writePos) = value;
Fw::writeLE16(m_buffer + m_writePos, value);
m_writePos += 2;
m_messageSize += 2;
}
@ -52,7 +52,7 @@ void OutputMessage::addU16(uint16 value)
void OutputMessage::addU32(uint32 value)
{
checkWrite(4);
*(uint32*)(m_buffer + m_writePos) = value;
Fw::writeLE32(m_buffer + m_writePos, value);
m_writePos += 4;
m_messageSize += 4;
}
@ -60,7 +60,7 @@ void OutputMessage::addU32(uint32 value)
void OutputMessage::addU64(uint64 value)
{
checkWrite(8);
*(uint64*)(m_buffer + m_writePos) = value;
Fw::writeLE64(m_buffer + m_writePos, value);
m_writePos += 8;
m_messageSize += 8;
}

View File

@ -56,6 +56,14 @@ inline uint32 getU32(std::istream& in) {
return tmp;
}
inline uint16 readLE16(uchar *addr) { return (uint16)addr[1] << 8 | addr[0]; }
inline uint32 readLE32(uchar *addr) { return (uint32)readLE16(addr + 2) << 16 | readLE16(addr); }
inline uint64 readLE64(uchar *addr) { return (uint64)readLE32(addr + 4) << 32 | readLE32(addr); }
inline void writeLE16(uchar *addr, uint16 value) { addr[1] = value >> 8; addr[0] = (uint8)value; }
inline void writeLE32(uchar *addr, uint32 value) { writeLE16(addr + 2, value >> 16); writeLE16(addr, (uint16)value); }
inline void writeLE64(uchar *addr, uint64 value) { writeLE16(addr + 4, value >> 32); writeLE32(addr, (uint32)value); }
// fills an ostream by concatenating args
inline void fillOstream(std::ostringstream&) { }
template<class T, class... Args>