By definition, __attribute__they are not tolerated. If you want your data to be in a specific way, the Plan9 solution usually uses arrays unsigned charin your structure:
struct foo {
uchar data1[4];
uchar other[2];
}
Usually there will be no alignment, since it mainly uses unsigned characters. Of course, if you have high pain tolerance, you can always use enumbiases:
enum { FOO_DATA1=0, FOO_OTHER=4, FOO_LAST=6 };
Then you can download it like this:
unsigned char foo[FOO_LAST];
uint32_t n = htonl(val)
memcpy(foo+FOO_DATA1, &n, sizeof n)
memcpy(foo+FOO_OTHER, &some_16_bit_val, sizeof some_16_bit_val)
As long as you have a stomach, it will be fully portable.
source
share