summaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/codegen_decl.c4
-rw-r--r--src/codegen/compat.h6
2 files changed, 9 insertions, 1 deletions
diff --git a/src/codegen/codegen_decl.c b/src/codegen/codegen_decl.c
index 31513ef..0b78676 100644
--- a/src/codegen/codegen_decl.c
+++ b/src/codegen/codegen_decl.c
@@ -85,7 +85,11 @@ void emit_preamble(ParserContext *ctx, FILE *out)
else
{
// C mode
+ fputs("#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202300L\n", out);
+ fputs("#define ZC_AUTO auto\n", out);
+ fputs("#else\n", out);
fputs("#define ZC_AUTO __auto_type\n", out);
+ fputs("#endif\n", out);
fputs("#define ZC_CAST(T, x) ((T)(x))\n", out);
fputs(ZC_TCC_COMPAT_STR, out);
fputs("static inline const char* _z_bool_str(_Bool b) { return b ? \"true\" : "
diff --git a/src/codegen/compat.h b/src/codegen/compat.h
index 63a5af5..f8d9a4e 100644
--- a/src/codegen/compat.h
+++ b/src/codegen/compat.h
@@ -14,7 +14,11 @@
#define ZC_EXTERN_C_END }
#else
/* C mode */
-#define ZC_AUTO __auto_type ///< Auto type inference.
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202300L
+#define ZC_AUTO auto ///< C23 standard auto.
+#else
+#define ZC_AUTO __auto_type ///< GCC/Clang extension.
+#endif
#define ZC_CAST(T, x) ((T)(x)) ///< Explicit cast.
#define ZC_REINTERPRET(T, x) ((T)(x)) ///< Reinterpret cast.
#define ZC_EXTERN_C ///< Extern "C" (no-op in C).