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/transform.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 '')
| -rw-r--r-- | src/core/transform.h | 17 |
1 files changed, 9 insertions, 8 deletions
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 @@ | |||
| 17 | invertco(compose(compose(TRANS_CUBE_ ## T, c), \ | 17 | invertco(compose(compose(TRANS_CUBE_ ## T, c), \ |
| 18 | TRANS_CUBE_ ## T ## _INVERSE)) | 18 | TRANS_CUBE_ ## T ## _INVERSE)) |
| 19 | 19 | ||
| 20 | STATIC uint8_t readtrans(const char [static NISSY_SIZE_TRANSFORMATION]); | 20 | STATIC uint8_t readtrans(const char [SIZE(NISSY_SIZE_TRANSFORMATION)]); |
| 21 | STATIC uint8_t readrotation(const char [static 2]); | 21 | STATIC uint8_t readrotation(const char [SIZE(2)]); |
| 22 | STATIC void writetrans(uint8_t, char [static NISSY_SIZE_TRANSFORMATION]); | 22 | STATIC void writetrans(uint8_t, char [SIZE(NISSY_SIZE_TRANSFORMATION)]); |
| 23 | 23 | ||
| 24 | STATIC cube_t transform_edges(cube_t, uint8_t); | 24 | STATIC cube_t transform_edges(cube_t, uint8_t); |
| 25 | STATIC cube_t transform_corners(cube_t, uint8_t); | 25 | STATIC cube_t transform_corners(cube_t, uint8_t); |
| @@ -29,7 +29,7 @@ STATIC_INLINE uint8_t inverse_trans(uint8_t); | |||
| 29 | STATIC uint64_t symmetry_mask(cube_t); | 29 | STATIC uint64_t symmetry_mask(cube_t); |
| 30 | 30 | ||
| 31 | STATIC uint8_t | 31 | STATIC uint8_t |
| 32 | readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) | 32 | readtrans(const char buf[SIZE(NISSY_SIZE_TRANSFORMATION)]) |
| 33 | { | 33 | { |
| 34 | uint8_t t; | 34 | uint8_t t; |
| 35 | 35 | ||
| @@ -41,7 +41,7 @@ readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) | |||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | STATIC uint8_t | 43 | STATIC uint8_t |
| 44 | readrotation(const char buf[static 2]) | 44 | readrotation(const char buf[SIZE(2)]) |
| 45 | { | 45 | { |
| 46 | char trans_str[NISSY_SIZE_TRANSFORMATION]; | 46 | char trans_str[NISSY_SIZE_TRANSFORMATION]; |
| 47 | 47 | ||
| @@ -53,7 +53,7 @@ readrotation(const char buf[static 2]) | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | STATIC void | 55 | STATIC void |
| 56 | writetrans(uint8_t t, char buf[static NISSY_SIZE_TRANSFORMATION]) | 56 | writetrans(uint8_t t, char buf[SIZE(NISSY_SIZE_TRANSFORMATION)]) |
| 57 | { | 57 | { |
| 58 | if (t >= 48) | 58 | if (t >= 48) |
| 59 | memcpy(buf, "error trans", 11); | 59 | memcpy(buf, "error trans", 11); |
| @@ -407,12 +407,13 @@ inverse_trans(uint8_t t) | |||
| 407 | STATIC uint64_t | 407 | STATIC uint64_t |
| 408 | symmetry_mask(cube_t cube) | 408 | symmetry_mask(cube_t cube) |
| 409 | { | 409 | { |
| 410 | uint64_t t, ret; | 410 | uint64_t ret; |
| 411 | uint8_t t; | ||
| 411 | cube_t transformed; | 412 | cube_t transformed; |
| 412 | 413 | ||
| 413 | for (t = 0, ret = 0; t < NTRANS; t++) { | 414 | for (t = 0, ret = 0; t < NTRANS; t++) { |
| 414 | transformed = transform(cube, t); | 415 | transformed = transform(cube, t); |
| 415 | ret |= ((uint64_t)equal(cube, transformed)) << t; | 416 | ret |= ((uint64_t)equal(cube, transformed)) << (uint64_t)t; |
| 416 | } | 417 | } |
| 417 | 418 | ||
| 418 | return ret; | 419 | return ret; |
