On 2008-02-14, Oleg Verych <[email protected]> wrote:

>>> But how efficient it can be? Better to have good _design_
>>> right from the start.
>>
>> If you don't get to define the layout of the data in memory, I
>> don't see how you can "design" your way around doing byte by
>> byte access of misaligned values.
>
> For this case
>
>| typedef struct tTestPointer
>|   {
>|     uint8_t m;
>|     uint16_t k;
>|     uint32_t l;
>|   } __attribute__ ((packed)) tTestPointer;
>
> padding can be inserted after 'm' (gcc) or *before* (by design). Latter,
> as it seems, is going to work for wire protocols without overhead. No?

Yes.  But that's a very specially contrived case.  In the wild,
The chances that you can get all of the fields in a struct to
align by adding padding at the beginning of the structure are
going to be pretty slim.

struct t
{
uint16_t u1;
uint8_t  b1;
uint16_t u2;
}

If you have to deal with data layed out like that, there's
nothing you can do besides doing byte-by-byte access of the
misaligned fields.  You simply can't have both u1 and u2
aligned.

-- 
Grant Edwards                   grante             Yow! I just went below the
                                  at               poverty line!
                               visi.com            


Reply via email to