diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-04-06 15:55:33 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-04-06 15:55:33 +0200 |
| commit | fc41f7917531693680b5baf71ffe38c47333fe84 (patch) | |
| tree | a6e62232e05e7779034c5f9d1bf743b6f1c198e3 /src/utils | |
| parent | fe534f1497da6447153064d7bba00243000f803b (diff) | |
| download | nissy-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.h | 17 | ||||
| -rw-r--r-- | src/utils/dbg_log.h | 3 | ||||
| -rw-r--r-- | src/utils/math.h | 6 | ||||
| -rw-r--r-- | src/utils/wrapthread.h | 4 |
4 files changed, 20 insertions, 10 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 | /* |
| 16 | For example MSVC, which is not fully C11 compliant (e.g. it does not support | ||
| 17 | a[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 |
diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h index d737ff2..08d42a3 100644 --- a/src/utils/dbg_log.h +++ b/src/utils/dbg_log.h | |||
| @@ -7,8 +7,7 @@ void write_wrapper(void (*)(const char *, void *), const char *, ...); | |||
| 7 | void | 7 | void |
| 8 | write_wrapper(void (*write)(const char *, void *), const char *str, ...) | 8 | write_wrapper(void (*write)(const char *, void *), const char *str, ...) |
| 9 | { | 9 | { |
| 10 | static const size_t len = 1000; | 10 | char message[1000]; |
| 11 | char message[len]; | ||
| 12 | va_list args; | 11 | va_list args; |
| 13 | 12 | ||
| 14 | va_start(args, str); | 13 | va_start(args, str); |
diff --git a/src/utils/math.h b/src/utils/math.h index f2176b6..0c56861 100644 --- a/src/utils/math.h +++ b/src/utils/math.h | |||
| @@ -73,10 +73,10 @@ indextoperm(uint64_t p, size_t n, uint8_t *r) | |||
| 73 | 73 | ||
| 74 | /* Find k-th unused number */ | 74 | /* Find k-th unused number */ |
| 75 | for (j = 0, c = 0; c <= k; j++) | 75 | for (j = 0, c = 0; c <= k; j++) |
| 76 | c += 1 - ((used & (1<<j)) >> j); | 76 | c += UINT64_C(1) - ((used & (UINT64_C(1)<<j)) >> j); |
| 77 | 77 | ||
| 78 | r[i] = j-1; | 78 | r[i] = (uint8_t)(j-1); |
| 79 | used |= 1 << (j-1); | 79 | used |= UINT64_C(1) << (j-1); |
| 80 | p %= factorial[n-i-1]; | 80 | p %= factorial[n-i-1]; |
| 81 | } | 81 | } |
| 82 | 82 | ||
diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h index 4ac72a6..9578293 100644 --- a/src/utils/wrapthread.h +++ b/src/utils/wrapthread.h | |||
| @@ -61,8 +61,8 @@ | |||
| 61 | #define wrapthread_return_t int | 61 | #define wrapthread_return_t int |
| 62 | #define wrapthread_return_val 0 | 62 | #define wrapthread_return_val 0 |
| 63 | 63 | ||
| 64 | #define wrapthread_define_var_thread_t(x) unused char x | 64 | #define wrapthread_define_var_thread_t(x) UNUSED char x |
| 65 | #define wrapthread_define_var_mutex_t(x) unused char x | 65 | #define wrapthread_define_var_mutex_t(x) UNUSED char x |
| 66 | #define wrapthread_define_struct_thread_t(x) char x | 66 | #define wrapthread_define_struct_thread_t(x) char x |
| 67 | #define wrapthread_define_struct_mutex_t(x) char x | 67 | #define wrapthread_define_struct_mutex_t(x) char x |
| 68 | 68 | ||
