From 56b9c92b9881527d05ea9caa34c2c87e5927aa71 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 25 Jul 2023 21:48:27 +0200 Subject: [PATCH] util: use C23 typeof if available Instead of using the non-standard __typeof__, prefer the standard typeof operator introduced in C23. Signed-off-by: Simon Ser --- src/wayland-util.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wayland-util.h b/src/wayland-util.h index 1a451e4..79aabc7 100644 --- a/src/wayland-util.h +++ b/src/wayland-util.h @@ -68,6 +68,12 @@ extern "C" { #define WL_PRINTF(x, y) #endif +#if __STDC_VERSION__ >= 202311L +#define WL_TYPEOF(expr) typeof(expr) +#else +#define WL_TYPEOF(expr) __typeof__(expr) +#endif + /** \class wl_object * * \brief A protocol object. @@ -406,8 +412,8 @@ wl_list_insert_list(struct wl_list *list, struct wl_list *other); * \return The container for the specified pointer */ #define wl_container_of(ptr, sample, member) \ - (__typeof__(sample))((char *)(ptr) - \ - offsetof(__typeof__(*sample), member)) + (WL_TYPEOF(sample))((char *)(ptr) - \ + offsetof(WL_TYPEOF(*sample), member)) /** * Iterates over a list.