From 944a02d18adfdf2184528baf053fcf0e06bd3486 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Sat, 4 Dec 2021 12:02:21 +0100 Subject: [PATCH] include: Add a macro to check pointer alignment Add a new macro, IS_PTR_ALIGNED() that verifies if a pointer is aligned sufficiently for a particular data type provided as an argument. Signed-off-by: Carles Cufi --- include/toolchain/common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/toolchain/common.h b/include/toolchain/common.h index 6b6df0f8d92..3da468286a3 100644 --- a/include/toolchain/common.h +++ b/include/toolchain/common.h @@ -187,6 +187,9 @@ */ #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type +/* Check if a pointer is aligned enough for a particular data type. */ +#define IS_PTR_ALIGNED(ptr, type) ((((uintptr_t)ptr) % __alignof(type)) == 0) + /** * @brief Iterable Sections APIs * @defgroup iterable_section_apis Iterable Sections APIs