aboutsummaryrefslogtreecommitdiff
path: root/src/utils/compilers.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-04-06 15:55:33 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-04-06 15:55:33 +0200
commitfc41f7917531693680b5baf71ffe38c47333fe84 (patch)
treea6e62232e05e7779034c5f9d1bf743b6f1c198e3 /src/utils/compilers.h
parentfe534f1497da6447153064d7bba00243000f803b (diff)
downloadnissy-core-fc41f7917531693680b5baf71ffe38c47333fe84.tar.gz
nissy-core-fc41f7917531693680b5baf71ffe38c47333fe84.zip
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.
Diffstat (limited to '')
-rw-r--r--src/utils/compilers.h17
1 files changed, 14 insertions, 3 deletions
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 @@
1#if defined(__GNUC__) 1#if defined(__GNUC__)
2 2
3#define unused __attribute__((unused)) 3#define UNUSED __attribute__((unused))
4#define SIZE(x) static (x)
5#define NON_NULL SIZE(1)
4 6
5#elif defined(__clang__) 7#elif defined(__clang__)
6 8
7#define unused __attribute__((unused)) 9#define UNUSED __attribute__((unused))
10#define SIZE(x) static (x)
11#define NON_NULL SIZE(1)
8 12
9#else 13#else
10 14
11#define unused 15/*
16For example MSVC, which is not fully C11 compliant (e.g. it does not support
17a[static N] notation for array parameters).
18*/
19
20#define UNUSED
21#define SIZE(x)
22#define NON_NULL
12 23
13#endif 24#endif

Generated with cgit - Back to sebastiano.tronto.net