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/solvers/coord/solve.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/solvers/coord/solve.h')
| -rw-r--r-- | src/solvers/coord/solve.h | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 9ea6d1a..6bb9af2 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -13,20 +13,20 @@ typedef struct { | |||
| 13 | const unsigned char *ptable; | 13 | const unsigned char *ptable; |
| 14 | } dfsarg_solve_coord_t; | 14 | } dfsarg_solve_coord_t; |
| 15 | 15 | ||
| 16 | STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, | 16 | STATIC int64_t solve_coord(oriented_cube_t, coord_t [NON_NULL], uint8_t, |
| 17 | uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | 17 | uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, |
| 18 | const unsigned char *, size_t, char *, int (*)(void *), void *); | 18 | const unsigned char *, size_t, char *, int (*)(void *), void *); |
| 19 | STATIC long long solve_coord_dispatch(oriented_cube_t, const char *, unsigned, | 19 | STATIC long long solve_coord_dispatch(oriented_cube_t, const char *, unsigned, |
| 20 | unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, | 20 | unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long, |
| 21 | const unsigned char *, unsigned, char *, | 21 | const unsigned char *, unsigned, char *, |
| 22 | long long [static NISSY_SIZE_SOLVE_STATS], int (*)(void *), void *); | 22 | long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *); |
| 23 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); | 23 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [NON_NULL]); |
| 24 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); | 24 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [NON_NULL]); |
| 25 | STATIC bool coord_continue_oninverse(const dfsarg_solve_coord_t [static 1]); | 25 | STATIC bool coord_continue_oninverse(const dfsarg_solve_coord_t [NON_NULL]); |
| 26 | STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t [static 1]); | 26 | STATIC int64_t solve_coord_dfs(dfsarg_solve_coord_t [NON_NULL]); |
| 27 | 27 | ||
| 28 | STATIC bool | 28 | STATIC bool |
| 29 | coord_solution_admissible(const dfsarg_solve_coord_t arg[static 1]) | 29 | coord_solution_admissible(const dfsarg_solve_coord_t arg[NON_NULL]) |
| 30 | { | 30 | { |
| 31 | uint8_t n; | 31 | uint8_t n; |
| 32 | 32 | ||
| @@ -39,7 +39,7 @@ coord_solution_admissible(const dfsarg_solve_coord_t arg[static 1]) | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | STATIC bool | 41 | STATIC bool |
| 42 | coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1]) | 42 | coord_continue_onnormal(const dfsarg_solve_coord_t arg[NON_NULL]) |
| 43 | { | 43 | { |
| 44 | uint8_t flag, nn, ni, swbound_n, swbound_i, pval; | 44 | uint8_t flag, nn, ni, swbound_n, swbound_i, pval; |
| 45 | uint64_t coord; | 45 | uint64_t coord; |
| @@ -93,7 +93,7 @@ coord_continue_onnormal(const dfsarg_solve_coord_t arg[static 1]) | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | STATIC bool | 95 | STATIC bool |
| 96 | coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1]) | 96 | coord_continue_oninverse(const dfsarg_solve_coord_t arg[NON_NULL]) |
| 97 | { | 97 | { |
| 98 | uint8_t flag, nn, ni, swbound_n, swbound_i, pval; | 98 | uint8_t flag, nn, ni, swbound_n, swbound_i, pval; |
| 99 | uint64_t coord; | 99 | uint64_t coord; |
| @@ -147,12 +147,11 @@ coord_continue_oninverse(const dfsarg_solve_coord_t arg[static 1]) | |||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | STATIC int64_t | 149 | STATIC int64_t |
| 150 | solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | 150 | solve_coord_dfs(dfsarg_solve_coord_t arg[NON_NULL]) |
| 151 | { | 151 | { |
| 152 | bool lastbackup; | 152 | bool lastbackup; |
| 153 | uint8_t m, l, nnbackup, nibackup, nmoves; | 153 | uint8_t m, l, nnbackup, nibackup, nmoves; |
| 154 | uint32_t mm; | 154 | uint64_t mm, coord; |
| 155 | uint64_t coord; | ||
| 156 | int64_t n, ret; | 155 | int64_t n, ret; |
| 157 | cube_t backup_cube, backup_inverse; | 156 | cube_t backup_cube, backup_inverse; |
| 158 | 157 | ||
| @@ -190,7 +189,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 190 | arg->lastisnormal = true; | 189 | arg->lastisnormal = true; |
| 191 | 190 | ||
| 192 | for (m = 0; m < NMOVES; m++) { | 191 | for (m = 0; m < NMOVES; m++) { |
| 193 | if (!(mm & (UINT32_C(1) << (uint32_t)m))) | 192 | if (!(mm & (UINT64_C(1) << (uint64_t)m))) |
| 194 | continue; | 193 | continue; |
| 195 | 194 | ||
| 196 | arg->solution_moves->moves[l] = m; | 195 | arg->solution_moves->moves[l] = m; |
| @@ -221,7 +220,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 221 | arg->lastisnormal = false; | 220 | arg->lastisnormal = false; |
| 222 | 221 | ||
| 223 | for (m = 0; m < NMOVES; m++) { | 222 | for (m = 0; m < NMOVES; m++) { |
| 224 | if (!(mm & (UINT32_C(1) << (uint32_t)m))) | 223 | if (!(mm & (UINT64_C(1) << (uint64_t)m))) |
| 225 | continue; | 224 | continue; |
| 226 | 225 | ||
| 227 | arg->solution_moves->premoves[l] = m; | 226 | arg->solution_moves->premoves[l] = m; |
| @@ -258,7 +257,7 @@ solve_coord_dispatch( | |||
| 258 | const unsigned char *data, | 257 | const unsigned char *data, |
| 259 | unsigned solutions_size, | 258 | unsigned solutions_size, |
| 260 | char *sols, | 259 | char *sols, |
| 261 | long long stats[static NISSY_SIZE_SOLVE_STATS], | 260 | long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)], |
| 262 | int (*poll_status)(void *), | 261 | int (*poll_status)(void *), |
| 263 | void *poll_status_data | 262 | void *poll_status_data |
| 264 | ) | 263 | ) |
| @@ -280,15 +279,16 @@ solve_coord_dispatch( | |||
| 280 | return NISSY_ERROR_INVALID_SOLVER; | 279 | return NISSY_ERROR_INVALID_SOLVER; |
| 281 | } | 280 | } |
| 282 | 281 | ||
| 283 | return solve_coord(oc, coord, trans, nissflag, minmoves, maxmoves, | 282 | return solve_coord(oc, coord, trans, (uint8_t)nissflag, |
| 284 | maxsolutions, optimal, threads, data_size, data, | 283 | (uint8_t)minmoves, (uint8_t)maxmoves, (uint8_t)maxsolutions, |
| 284 | (uint8_t)optimal, (uint8_t)threads, data_size, data, | ||
| 285 | solutions_size, sols, poll_status, poll_status_data); | 285 | solutions_size, sols, poll_status, poll_status_data); |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | STATIC int64_t | 288 | STATIC int64_t |
| 289 | solve_coord( | 289 | solve_coord( |
| 290 | oriented_cube_t oc, | 290 | oriented_cube_t oc, |
| 291 | coord_t coord [static 1], | 291 | coord_t coord [NON_NULL], |
| 292 | uint8_t trans, | 292 | uint8_t trans, |
| 293 | uint8_t nissflag, | 293 | uint8_t nissflag, |
| 294 | uint8_t minmoves, | 294 | uint8_t minmoves, |
