From 9722027fc155787830eebe74263fd9169937bba9 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 20 Feb 2022 03:18:47 -0800 Subject: [PATCH] Add macro to cast function pointer to void pointer Does not evaluate constant expression, I don't know if that's possible. --- src/doomtype.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/doomtype.h b/src/doomtype.h index 7e91ed7e4..c6cde7b6b 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -409,4 +409,12 @@ typedef UINT64 precise_t; #define intsign(n) \ ((n) < 0 ? -1 : (n) > 0 ? 1 : 0) +// ISO C forbids function pointer -> void pointer cast but +// if it's wrapped in a struct, we can take a pointer to +// that struct and it's fine... + +// Cast function pointer to (void*) +#define FUNCPTRCAST(p) ((union{void(*f)(void);void*v;})\ + {(void(*)(void))p}).v + #endif //__DOOMTYPE__