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 <contact@emersion.fr>
This commit is contained in:
Simon Ser 2023-07-25 21:48:27 +02:00 committed by Daniel Stone
parent dc1da181db
commit 56b9c92b98

View file

@ -68,6 +68,12 @@ extern "C" {
#define WL_PRINTF(x, y) #define WL_PRINTF(x, y)
#endif #endif
#if __STDC_VERSION__ >= 202311L
#define WL_TYPEOF(expr) typeof(expr)
#else
#define WL_TYPEOF(expr) __typeof__(expr)
#endif
/** \class wl_object /** \class wl_object
* *
* \brief A protocol 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 * \return The container for the specified pointer
*/ */
#define wl_container_of(ptr, sample, member) \ #define wl_container_of(ptr, sample, member) \
(__typeof__(sample))((char *)(ptr) - \ (WL_TYPEOF(sample))((char *)(ptr) - \
offsetof(__typeof__(*sample), member)) offsetof(WL_TYPEOF(*sample), member))
/** /**
* Iterates over a list. * Iterates over a list.