fix compilation for compilers which don't set __WORDSIZE

Sun, 15 Dec 2024 15:41:18 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 15 Dec 2024 15:41:18 +0100
changeset 1018
c773da859bad
parent 1017
b0098854071f
child 1019
09c6fe8fe3b9

fix compilation for compilers which don't set __WORDSIZE

src/array_list.c file | annotate | diff | comparison | revisions
src/cx/common.h file | annotate | diff | comparison | revisions
--- a/src/array_list.c	Sun Dec 15 15:23:29 2024 +0100
+++ b/src/array_list.c	Sun Dec 15 15:41:18 2024 +0100
@@ -108,7 +108,7 @@
     size_t oldcap;
     size_t oldsize;
     size_t max_size;
-    if (width == 0 || width == __WORDSIZE) {
+    if (width == 0 || width == CX_WORDSIZE) {
         oldcap = *(size_t*) capacity;
         oldsize = *(size_t*) size;
         max_size = SIZE_MAX;
@@ -121,7 +121,7 @@
         oldsize = *(uint8_t*) size;
         max_size = UINT8_MAX;
     }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
     else if (width == 32) {
         oldcap = *(uint32_t*) capacity;
         oldsize = *(uint32_t*) size;
@@ -162,14 +162,14 @@
         *array = newmem;
 
         // store new capacity
-        if (width == 0 || width == __WORDSIZE) {
+        if (width == 0 || width == CX_WORDSIZE) {
             *(size_t*) capacity = newcap;
         } else if (width == 16) {
             *(uint16_t*) capacity = newcap;
         } else if (width == 8) {
             *(uint8_t*) capacity = newcap;
         }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
         else if (width == 32) {
             *(uint32_t*) capacity = newcap;
         }
@@ -201,7 +201,7 @@
     size_t oldcap;
     size_t oldsize;
     size_t max_size;
-    if (width == 0 || width == __WORDSIZE) {
+    if (width == 0 || width == CX_WORDSIZE) {
         oldcap = *(size_t*) capacity;
         oldsize = *(size_t*) size;
         max_size = SIZE_MAX;
@@ -214,7 +214,7 @@
         oldsize = *(uint8_t*) size;
         max_size = UINT8_MAX;
     }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
     else if (width == 32) {
         oldcap = *(uint32_t*) capacity;
         oldsize = *(uint32_t*) size;
@@ -278,7 +278,7 @@
 
     // if any of size or capacity changed, store them back
     if (newsize != oldsize || newcap != oldcap) {
-        if (width == 0 || width == __WORDSIZE) {
+        if (width == 0 || width == CX_WORDSIZE) {
             *(size_t*) capacity = newcap;
             *(size_t*) size = newsize;
         } else if (width == 16) {
@@ -288,7 +288,7 @@
             *(uint8_t*) capacity = newcap;
             *(uint8_t*) size = newsize;
         }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
         else if (width == 32) {
             *(uint32_t*) capacity = newcap;
             *(uint32_t*) size = newsize;
--- a/src/cx/common.h	Sun Dec 15 15:23:29 2024 +0100
+++ b/src/cx/common.h	Sun Dec 15 15:41:18 2024 +0100
@@ -99,6 +99,18 @@
 #include <sys/types.h>
 
 // ---------------------------------------------------------------------------
+//       Architecture Detection
+// ---------------------------------------------------------------------------
+
+#if INTPTR_MAX == INT64_MAX
+#define CX_WORDSIZE 64
+#elif INTPTR_MAX == INT32_MAX
+#define CX_WORDSIZE 32
+#else
+#error Unknown pointer size or missing size macros!
+#endif
+
+// ---------------------------------------------------------------------------
 //       Attribute definitions
 // ---------------------------------------------------------------------------
 

mercurial