RE: [Bluez-devel] Alignment issue

David Woodhouse
2004-08-12T12:53:30Z

On Thu, 2004-08-12 at 12:22 +0200, Marcel Holtmann wrote:
> For now I will use memmove, but we need clarification on this. I lost my
> Sun Ultra system, so I can't do any tests.
>
> Please send me the additional compiler defines for architectures that
> can do unaligned access by themself.

These should do it right on all architectures -- I've checked with a gcc
hacker and verified that at least the get_unaligned() version does the
right thing on both FR-V and i386. On FR-V it loads each byte and shifts
it into place, while on i386 it just loads it.

#define get_unaligned(ptr) \
({ \
struct __attribute__((packed)) { \
typeof(*(ptr)) __v; \
} *__p = (ptr); \
__p->__v; \
})

#define put_unaligned(ptr, val) \
do { \
struct __attribute__((packed)) { \
typeof(*(ptr)) __v; \
} *__p = (ptr); \
__p->__v = (val); \
} while(0)

--
dwmw2