Browse Source

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>
master
Luiz Augusto von Dentz 8 years ago committed by Anas Nashif
parent
commit
9ef64a3112
  1. 9
      include/toolchain/gcc.h

9
include/toolchain/gcc.h

@ -87,6 +87,15 @@ @@ -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…
Cancel
Save