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/core/cube.h | 8 ++++---- src/core/moves.h | 30 +++++++++++++++--------------- src/core/transform.h | 17 +++++++++-------- 3 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src/core') diff --git a/src/core/cube.h b/src/core/cube.h index 9e79dda..1c21ce1 100644 --- a/src/core/cube.h +++ b/src/core/cube.h @@ -1,6 +1,6 @@ STATIC bool cube_true(cube_t); -STATIC cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); +STATIC cube_t cubefromarray(uint8_t [SIZE(8)], uint8_t [SIZE(12)]); STATIC bool isconsistent(oriented_cube_t); STATIC bool issolvable(oriented_cube_t); STATIC bool issolved(oriented_cube_t); @@ -10,7 +10,7 @@ STATIC void getcube_fix(long long *, long long *, STATIC cube_t getcube(uint64_t, uint64_t, uint64_t, uint64_t); STATIC oriented_cube_t readcube(const char *); -STATIC int64_t writecube(oriented_cube_t, size_t n, char [n]); +STATIC int64_t writecube(oriented_cube_t, size_t n, char *); STATIC uint8_t readco(const char *); STATIC uint8_t readcp(const char *); STATIC uint8_t readeo(const char *); @@ -29,7 +29,7 @@ cube_true(cube_t cube) } STATIC cube_t -cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) +cubefromarray(uint8_t c[SIZE(8)], uint8_t e[SIZE(12)]) { return STATIC_CUBE( c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], @@ -304,7 +304,7 @@ readcube(const char *buf) } STATIC int64_t -writecube(oriented_cube_t cube, size_t buf_size, char buf[buf_size]) +writecube(oriented_cube_t cube, size_t buf_size, char *buf) { int i; uint8_t corner[8], edge[12]; 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 @@ STATIC uint8_t readmove(char); STATIC int64_t readmoves(const char *, size_t, size_t, size_t *, size_t *, uint8_t *, uint8_t *); -STATIC int64_t readmoves_struct(const char *, moves_struct_t [static 1]); +STATIC int64_t readmoves_struct(const char *, moves_struct_t [NON_NULL]); STATIC int64_t countmoves(const char *); STATIC bool moves_struct_equal( - const moves_struct_t [static 1], const moves_struct_t [static 1]); + const moves_struct_t [NON_NULL], const moves_struct_t [NON_NULL]); STATIC long long comparemoves(const char *, const char *); STATIC uint8_t readmodifier(char); STATIC int64_t writemoves(size_t, const uint8_t *, size_t, char *); STATIC int64_t writemoves_struct( - const moves_struct_t [static 1], size_t, char *); + const moves_struct_t [NON_NULL], size_t, char *); STATIC_INLINE bool allowednextmove(uint8_t, uint8_t); STATIC bool allowedmoves(size_t, const uint8_t *); @@ -36,9 +36,9 @@ STATIC bool are_lastmoves_singlecw(size_t, const uint8_t*); STATIC int64_t move_variations(const char *, const char *, size_t, char *); STATIC int64_t move_variations_lastqt( - const moves_struct_t [static 1], size_t, char *); + const moves_struct_t [NON_NULL], size_t, char *); STATIC int64_t move_variations_unniss( - const moves_struct_t [static 1], size_t, char *); + const moves_struct_t [NON_NULL], size_t, char *); #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ RET_ERROR, ARG_ACTION) \ @@ -167,7 +167,7 @@ readmoves( } STATIC int64_t -readmoves_struct(const char *moves, moves_struct_t ret[static 1]) +readmoves_struct(const char *moves, moves_struct_t ret[NON_NULL]) { return readmoves(moves, NISSY_SIZE_MOVES, NISSY_SIZE_MOVES, &ret->nnormal, &ret->ninverse, ret->normal, ret->inverse); @@ -190,8 +190,8 @@ countmoves(const char *buf) STATIC bool moves_struct_equal( - const moves_struct_t ms1[static 1], - const moves_struct_t ms2[static 1] + const moves_struct_t ms1[NON_NULL], + const moves_struct_t ms2[NON_NULL] ) { size_t i; @@ -281,7 +281,7 @@ writemoves_error: STATIC int64_t writemoves_struct( - const moves_struct_t moves[static 1], + const moves_struct_t moves[NON_NULL], size_t buf_size, char *buf ) @@ -612,7 +612,7 @@ move_variations( STATIC int64_t move_variations_lastqt( - const moves_struct_t s[static 1], + const moves_struct_t s[NON_NULL], size_t result_size, char *result ) @@ -623,10 +623,10 @@ move_variations_lastqt( size_t u; moves_struct_t ss; - in1 = s->nnormal-1; - in2 = s->nnormal-2; - ii1 = s->ninverse-1; - ii2 = s->ninverse-2; + in1 = (uint8_t)(s->nnormal-1); + in2 = (uint8_t)(s->nnormal-2); + ii1 = (uint8_t)(s->ninverse-1); + ii2 = (uint8_t)(s->ninverse-2); n1 = in1 >= 0 ? s->normal[in1] : UINT8_ERROR; n2 = in2 >= 0 ? s->normal[in2] : UINT8_ERROR; @@ -686,7 +686,7 @@ lastqt_error: STATIC int64_t move_variations_unniss( - const moves_struct_t s[static 1], + const moves_struct_t s[NON_NULL], size_t result_size, char *result ) diff --git a/src/core/transform.h b/src/core/transform.h index f19c44f..af4634e 100644 --- a/src/core/transform.h +++ b/src/core/transform.h @@ -17,9 +17,9 @@ invertco(compose(compose(TRANS_CUBE_ ## T, c), \ TRANS_CUBE_ ## T ## _INVERSE)) -STATIC uint8_t readtrans(const char [static NISSY_SIZE_TRANSFORMATION]); -STATIC uint8_t readrotation(const char [static 2]); -STATIC void writetrans(uint8_t, char [static NISSY_SIZE_TRANSFORMATION]); +STATIC uint8_t readtrans(const char [SIZE(NISSY_SIZE_TRANSFORMATION)]); +STATIC uint8_t readrotation(const char [SIZE(2)]); +STATIC void writetrans(uint8_t, char [SIZE(NISSY_SIZE_TRANSFORMATION)]); STATIC cube_t transform_edges(cube_t, uint8_t); STATIC cube_t transform_corners(cube_t, uint8_t); @@ -29,7 +29,7 @@ STATIC_INLINE uint8_t inverse_trans(uint8_t); STATIC uint64_t symmetry_mask(cube_t); STATIC uint8_t -readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) +readtrans(const char buf[SIZE(NISSY_SIZE_TRANSFORMATION)]) { uint8_t t; @@ -41,7 +41,7 @@ readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) } STATIC uint8_t -readrotation(const char buf[static 2]) +readrotation(const char buf[SIZE(2)]) { char trans_str[NISSY_SIZE_TRANSFORMATION]; @@ -53,7 +53,7 @@ readrotation(const char buf[static 2]) } STATIC void -writetrans(uint8_t t, char buf[static NISSY_SIZE_TRANSFORMATION]) +writetrans(uint8_t t, char buf[SIZE(NISSY_SIZE_TRANSFORMATION)]) { if (t >= 48) memcpy(buf, "error trans", 11); @@ -407,12 +407,13 @@ inverse_trans(uint8_t t) STATIC uint64_t symmetry_mask(cube_t cube) { - uint64_t t, ret; + uint64_t ret; + uint8_t t; cube_t transformed; for (t = 0, ret = 0; t < NTRANS; t++) { transformed = transform(cube, t); - ret |= ((uint64_t)equal(cube, transformed)) << t; + ret |= ((uint64_t)equal(cube, transformed)) << (uint64_t)t; } return ret; -- cgit v1.3