lib/cast.h: const_cast(): Reimplement with _Generic(3)

This makes it much simpler and portable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2024-05-15 13:19:43 +02:00 committed by Iker Pedrosa
parent 4e2453fa9f
commit 69f74dbf8a

View File

@ -8,14 +8,8 @@
#include <config.h>
#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