aboutsummaryrefslogtreecommitdiff
path: root/src/core/transform.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-04-06 15:55:33 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-04-06 15:55:33 +0200
commitfc41f7917531693680b5baf71ffe38c47333fe84 (patch)
treea6e62232e05e7779034c5f9d1bf743b6f1c198e3 /src/core/transform.h
parentfe534f1497da6447153064d7bba00243000f803b (diff)
downloadnissy-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.h17
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
20STATIC uint8_t readtrans(const char [static NISSY_SIZE_TRANSFORMATION]); 20STATIC uint8_t readtrans(const char [SIZE(NISSY_SIZE_TRANSFORMATION)]);
21STATIC uint8_t readrotation(const char [static 2]); 21STATIC uint8_t readrotation(const char [SIZE(2)]);
22STATIC void writetrans(uint8_t, char [static NISSY_SIZE_TRANSFORMATION]); 22STATIC void writetrans(uint8_t, char [SIZE(NISSY_SIZE_TRANSFORMATION)]);
23 23
24STATIC cube_t transform_edges(cube_t, uint8_t); 24STATIC cube_t transform_edges(cube_t, uint8_t);
25STATIC cube_t transform_corners(cube_t, uint8_t); 25STATIC cube_t transform_corners(cube_t, uint8_t);
@@ -29,7 +29,7 @@ STATIC_INLINE uint8_t inverse_trans(uint8_t);
29STATIC uint64_t symmetry_mask(cube_t); 29STATIC uint64_t symmetry_mask(cube_t);
30 30
31STATIC uint8_t 31STATIC uint8_t
32readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) 32readtrans(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
43STATIC uint8_t 43STATIC uint8_t
44readrotation(const char buf[static 2]) 44readrotation(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
55STATIC void 55STATIC void
56writetrans(uint8_t t, char buf[static NISSY_SIZE_TRANSFORMATION]) 56writetrans(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)
407STATIC uint64_t 407STATIC uint64_t
408symmetry_mask(cube_t cube) 408symmetry_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;

Generated with cgit - Back to sebastiano.tronto.net