aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB. Scott Michel <scooter.phd@gmail.com>2024-11-18 09:43:40 -0800
committerB. Scott Michel <scooter.phd@gmail.com>2024-11-18 11:59:16 -0800
commit480e4efd13ff06599be8201294a1757ca76cc74b (patch)
tree32a282628e16c9a24fa7b5730d887872d348da04 /src
parent4f27f209516d141cc5aecc39af0e8baa27326b5c (diff)
downloadslirp-480e4efd13ff06599be8201294a1757ca76cc74b.zip
slirp-480e4efd13ff06599be8201294a1757ca76cc74b.tar.gz
slirp-480e4efd13ff06599be8201294a1757ca76cc74b.tar.bz2
vmstate.h: Prefer __typeof__ vice typeof
Clang masquerading as gcc on macOS (i.e., "gcc") borks on typeof(), but happily accepts __typeof__(). N.B., __typeof__ has been accepted by GCC and Clang for a long time, and recently MS decided to support it as well.
Diffstat (limited to 'src')
-rw-r--r--src/vmstate.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/vmstate.h b/src/vmstate.h
index cd77c85..82dcec7 100644
--- a/src/vmstate.h
+++ b/src/vmstate.h
@@ -216,10 +216,16 @@ extern const VMStateInfo slirp_vmstate_info_nullptr;
extern const VMStateInfo slirp_vmstate_info_buffer;
extern const VMStateInfo slirp_vmstate_info_tmp;
-#ifdef __GNUC__
+/* __typeof__ is recommended for better portability over typeof.
+ *
+ * __typeof__ is available in GCC, Clang, Clang masquerading as gcc on macOS,
+ * as well as MSVC version 19.39.33428+. It's also part of C23.
+ */
+#if defined(__GNUC__) || defined(__clang__) || (_MSC_FULL_VER >= 193933428) || \
+ (__STDC_VERSION__ >= 202301L)
#define type_check_array(t1, t2, n) ((t1(*)[n])0 - (t2 *)0)
#define type_check_pointer(t1, t2) ((t1 **)0 - (t2 *)0)
-#define typeof_field(type, field) typeof(((type *)0)->field)
+#define typeof_field(type, field) __typeof__(((type *)0)->field)
#define type_check(t1, t2) ((t1 *)0 - (t2 *)0)
#else
#define type_check_array(t1, t2, n) 0