From 69f74dbf8a2341aa73dc3f2213102eae1a3e49e0 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 15 May 2024 13:19:43 +0200 Subject: [PATCH] lib/cast.h: const_cast(): Reimplement with _Generic(3) This makes it much simpler and portable. Signed-off-by: Alejandro Colomar --- lib/cast.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/cast.h b/lib/cast.h index 9229528d..5cbbcf6d 100644 --- a/lib/cast.h +++ b/lib/cast.h @@ -8,14 +8,8 @@ #include -#include "must_be.h" - -#define const_cast(T, p) \ -({ \ - static_assert(is_same_type(typeof(&*(p)), const T), ""); \ - (T) (p); \ -}) +#define const_cast(T, p) _Generic(p, const T: (T) (p)) #endif // include guard