From fc41f7917531693680b5baf71ffe38c47333fe84 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Apr 2026 15:55:33 +0200 Subject: Make the project build with Microsoft's broken C compiler. MSVC is not fully C11-compliant, even when compiling with /std:c11. Some changes were needed to make the codebase compatible. Notably, the notation a[static N] and a[n] for function parameters of array type is not supported, so that had to be hidden behind a macro. Atomic types are also an experimental feature, apparently, but at least they work with the correct compiler flag. One thing that MSVC does well, however, is warning on integer conversions on /W4 level. I am not sure if Clang and GCC have something similar, so I took this chance to fix some of these. --- src/utils/compilers.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/utils/compilers.h') diff --git a/src/utils/compilers.h b/src/utils/compilers.h index a7d6df5..1b175bb 100644 --- a/src/utils/compilers.h +++ b/src/utils/compilers.h @@ -1,13 +1,24 @@ #if defined(__GNUC__) -#define unused __attribute__((unused)) +#define UNUSED __attribute__((unused)) +#define SIZE(x) static (x) +#define NON_NULL SIZE(1) #elif defined(__clang__) -#define unused __attribute__((unused)) +#define UNUSED __attribute__((unused)) +#define SIZE(x) static (x) +#define NON_NULL SIZE(1) #else -#define unused +/* +For example MSVC, which is not fully C11 compliant (e.g. it does not support +a[static N] notation for array parameters). +*/ + +#define UNUSED +#define SIZE(x) +#define NON_NULL #endif -- cgit v1.3