toolchain/gcc: Add UNALIGNED_GET macro
Similar to PACK_STRUCT it provide safe access to possible unaligned data but it is much more convenient to use with non-struct types since all one need to do is add a cast e.g. UNALIGNED_GET((uint16_t *) data). Change-Id: I46402bdf1dd13081fe340a7214a84750a6cf04d2 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
06d380c2ba
commit
9ef64a3112
1 changed files with 9 additions and 0 deletions
|
@ -87,6 +87,15 @@
|
|||
while (0)
|
||||
#endif /* !CONFIG_UNALIGNED_WRITE_UNSUPPORTED */
|
||||
|
||||
/* Unaligned access */
|
||||
#define UNALIGNED_GET(p) \
|
||||
__extension__ ({ \
|
||||
struct __attribute__((__packed__)) { \
|
||||
__typeof__(*(p)) __v; \
|
||||
} *__p = (__typeof__(__p)) (p); \
|
||||
__p->__v; \
|
||||
})
|
||||
|
||||
#define _GENERIC_SECTION(segment) __attribute__((section(#segment)))
|
||||
|
||||
#define PACK_STRUCT __attribute__((__packed__))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue