util: add a alignof() macro
authorRhys Perry <pendingchaos02@gmail.com>
Thu, 6 Aug 2020 13:53:36 +0000 (14:53 +0100)
committerMarge Bot <eric+marge@anholt.net>
Thu, 20 Aug 2020 10:52:19 +0000 (10:52 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6206>

src/util/macros.h

index 04aec96b54667db9c9f8309e5618f6401dedbf5c..f9aa478c9949f52e2c75a2e04d7905a36a285c37 100644 (file)
@@ -351,4 +351,14 @@ enum pipe_debug_type
    PIPE_DEBUG_TYPE_CONFORMANCE,
 };
 
+#if !defined(alignof) && !defined(__cplusplus)
+#if __STDC_VERSION__ >= 201112L
+#define alignof(t) _Alignof(t)
+#elif defined(_MSC_VER)
+#define alignof(t) __alignof(t)
+#else
+#define alignof(t) __alignof__(t)
+#endif
+#endif
+
 #endif /* UTIL_MACROS_H */