I have a problem when using the uint32_t type from the stdint.h library. If I run the following code (on Ubuntu linux 11.10 x86_64, g++ version 4.6.1):
#include
You need to declare to the compiler to pack the structure
I believe that this will work for GCC
struct test
{
unsigned char field1;
unsigned short field2;
unsigned long field3;
} __attribute__((__packed__));
In MS it would be something using the pragma packed
http://www.cplusplus.com/forum/general/14659/
#pragma pack(push, 1) // exact fit - no padding
struct MyStruct
{
char b;
int a;
int array[2];
};
#pragma pack(pop) //back to whatever the previous packing mode was