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/core/moves.h | |
| 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 'src/core/moves.h')
| -rw-r--r-- | src/core/moves.h | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index 6169c6e..9f1f7cc 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -4,15 +4,15 @@ | |||
| 4 | STATIC uint8_t readmove(char); | 4 | STATIC uint8_t readmove(char); |
| 5 | STATIC int64_t readmoves(const char *, | 5 | STATIC int64_t readmoves(const char *, |
| 6 | size_t, size_t, size_t *, size_t *, uint8_t *, uint8_t *); | 6 | size_t, size_t, size_t *, size_t *, uint8_t *, uint8_t *); |
| 7 | STATIC int64_t readmoves_struct(const char *, moves_struct_t [static 1]); | 7 | STATIC int64_t readmoves_struct(const char *, moves_struct_t [NON_NULL]); |
| 8 | STATIC int64_t countmoves(const char *); | 8 | STATIC int64_t countmoves(const char *); |
| 9 | STATIC bool moves_struct_equal( | 9 | STATIC bool moves_struct_equal( |
| 10 | const moves_struct_t [static 1], const moves_struct_t [static 1]); | 10 | const moves_struct_t [NON_NULL], const moves_struct_t [NON_NULL]); |
| 11 | STATIC long long comparemoves(const char *, const char *); | 11 | STATIC long long comparemoves(const char *, const char *); |
| 12 | STATIC uint8_t readmodifier(char); | 12 | STATIC uint8_t readmodifier(char); |
| 13 | STATIC int64_t writemoves(size_t, const uint8_t *, size_t, char *); | 13 | STATIC int64_t writemoves(size_t, const uint8_t *, size_t, char *); |
| 14 | STATIC int64_t writemoves_struct( | 14 | STATIC int64_t writemoves_struct( |
| 15 | const moves_struct_t [static 1], size_t, char *); | 15 | const moves_struct_t [NON_NULL], size_t, char *); |
| 16 | 16 | ||
| 17 | STATIC_INLINE bool allowednextmove(uint8_t, uint8_t); | 17 | STATIC_INLINE bool allowednextmove(uint8_t, uint8_t); |
| 18 | STATIC bool allowedmoves(size_t, const uint8_t *); | 18 | STATIC bool allowedmoves(size_t, const uint8_t *); |
| @@ -36,9 +36,9 @@ STATIC bool are_lastmoves_singlecw(size_t, const uint8_t*); | |||
| 36 | 36 | ||
| 37 | STATIC int64_t move_variations(const char *, const char *, size_t, char *); | 37 | STATIC int64_t move_variations(const char *, const char *, size_t, char *); |
| 38 | STATIC int64_t move_variations_lastqt( | 38 | STATIC int64_t move_variations_lastqt( |
| 39 | const moves_struct_t [static 1], size_t, char *); | 39 | const moves_struct_t [NON_NULL], size_t, char *); |
| 40 | STATIC int64_t move_variations_unniss( | 40 | STATIC int64_t move_variations_unniss( |
| 41 | const moves_struct_t [static 1], size_t, char *); | 41 | const moves_struct_t [NON_NULL], size_t, char *); |
| 42 | 42 | ||
| 43 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ | 43 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ |
| 44 | RET_ERROR, ARG_ACTION) \ | 44 | RET_ERROR, ARG_ACTION) \ |
| @@ -167,7 +167,7 @@ readmoves( | |||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | STATIC int64_t | 169 | STATIC int64_t |
| 170 | readmoves_struct(const char *moves, moves_struct_t ret[static 1]) | 170 | readmoves_struct(const char *moves, moves_struct_t ret[NON_NULL]) |
| 171 | { | 171 | { |
| 172 | return readmoves(moves, NISSY_SIZE_MOVES, NISSY_SIZE_MOVES, | 172 | return readmoves(moves, NISSY_SIZE_MOVES, NISSY_SIZE_MOVES, |
| 173 | &ret->nnormal, &ret->ninverse, ret->normal, ret->inverse); | 173 | &ret->nnormal, &ret->ninverse, ret->normal, ret->inverse); |
| @@ -190,8 +190,8 @@ countmoves(const char *buf) | |||
| 190 | 190 | ||
| 191 | STATIC bool | 191 | STATIC bool |
| 192 | moves_struct_equal( | 192 | moves_struct_equal( |
| 193 | const moves_struct_t ms1[static 1], | 193 | const moves_struct_t ms1[NON_NULL], |
| 194 | const moves_struct_t ms2[static 1] | 194 | const moves_struct_t ms2[NON_NULL] |
| 195 | ) | 195 | ) |
| 196 | { | 196 | { |
| 197 | size_t i; | 197 | size_t i; |
| @@ -281,7 +281,7 @@ writemoves_error: | |||
| 281 | 281 | ||
| 282 | STATIC int64_t | 282 | STATIC int64_t |
| 283 | writemoves_struct( | 283 | writemoves_struct( |
| 284 | const moves_struct_t moves[static 1], | 284 | const moves_struct_t moves[NON_NULL], |
| 285 | size_t buf_size, | 285 | size_t buf_size, |
| 286 | char *buf | 286 | char *buf |
| 287 | ) | 287 | ) |
| @@ -612,7 +612,7 @@ move_variations( | |||
| 612 | 612 | ||
| 613 | STATIC int64_t | 613 | STATIC int64_t |
| 614 | move_variations_lastqt( | 614 | move_variations_lastqt( |
| 615 | const moves_struct_t s[static 1], | 615 | const moves_struct_t s[NON_NULL], |
| 616 | size_t result_size, | 616 | size_t result_size, |
| 617 | char *result | 617 | char *result |
| 618 | ) | 618 | ) |
| @@ -623,10 +623,10 @@ move_variations_lastqt( | |||
| 623 | size_t u; | 623 | size_t u; |
| 624 | moves_struct_t ss; | 624 | moves_struct_t ss; |
| 625 | 625 | ||
| 626 | in1 = s->nnormal-1; | 626 | in1 = (uint8_t)(s->nnormal-1); |
| 627 | in2 = s->nnormal-2; | 627 | in2 = (uint8_t)(s->nnormal-2); |
| 628 | ii1 = s->ninverse-1; | 628 | ii1 = (uint8_t)(s->ninverse-1); |
| 629 | ii2 = s->ninverse-2; | 629 | ii2 = (uint8_t)(s->ninverse-2); |
| 630 | 630 | ||
| 631 | n1 = in1 >= 0 ? s->normal[in1] : UINT8_ERROR; | 631 | n1 = in1 >= 0 ? s->normal[in1] : UINT8_ERROR; |
| 632 | n2 = in2 >= 0 ? s->normal[in2] : UINT8_ERROR; | 632 | n2 = in2 >= 0 ? s->normal[in2] : UINT8_ERROR; |
| @@ -686,7 +686,7 @@ lastqt_error: | |||
| 686 | 686 | ||
| 687 | STATIC int64_t | 687 | STATIC int64_t |
| 688 | move_variations_unniss( | 688 | move_variations_unniss( |
| 689 | const moves_struct_t s[static 1], | 689 | const moves_struct_t s[NON_NULL], |
| 690 | size_t result_size, | 690 | size_t result_size, |
| 691 | char *result | 691 | char *result |
| 692 | ) | 692 | ) |
