summaryrefslogtreecommitdiffstats
path: root/src/fundamental
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-12-05 23:11:13 +0100
committerLennart Poettering <lennart@poettering.net>2022-12-08 17:34:20 +0100
commit86bdf117148388a39f5d0c24e5259314f3e29fb5 (patch)
tree0e785c9c2f7c42acd13d7bc2635c6ff48346eed3 /src/fundamental
parentMerge pull request #25662 from msizanoen1/s2h-nosuspend-user-proc (diff)
downloadsystemd-86bdf117148388a39f5d0c24e5259314f3e29fb5.tar.xz
systemd-86bdf117148388a39f5d0c24e5259314f3e29fb5.zip
fundamental: add CAST_ALIGN_PTR() macro
Diffstat (limited to 'src/fundamental')
-rw-r--r--src/fundamental/macro-fundamental.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
index 65c9e042cd..db778c7609 100644
--- a/src/fundamental/macro-fundamental.h
+++ b/src/fundamental/macro-fundamental.h
@@ -354,6 +354,16 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
((l) + (ali) - 1) & ~((ali) - 1), \
VOID_0)
+/* Similar to ((t *) (void *) (p)) to cast a pointer. The macro asserts that the pointer has a suitable
+ * alignment for type "t". This exists for places where otherwise "-Wcast-align=strict" would issue a
+ * warning or if you want to assert that the cast gives a pointer of suitable alignment. */
+#define CAST_ALIGN_PTR(t, p) \
+ ({ \
+ const void *_p = (p); \
+ assert(((uintptr_t) _p) % __alignof__(t) == 0); \
+ (t *) _p; \
+ })
+
#define UPDATE_FLAG(orig, flag, b) \
((b) ? ((orig) | (flag)) : ((orig) & ~(flag)))
#define SET_FLAG(v, flag, b) \