bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] lib: make CHAR_MAX dependant on signedness of char


From: Ekaitz Zarraga
Subject: [PATCH 1/2] lib: make CHAR_MAX dependant on signedness of char
Date: Tue, 5 Mar 2024 13:17:47 +0100

* include/stdint.h (CHAR_MIN): Assign according to char signedness.
 (CHAR_MAX): Likewise.
---
 include/stdint.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/stdint.h b/include/stdint.h
index 694840dc..321be21c 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -2,6 +2,7 @@
  * GNU Mes --- Maxwell Equations of Software
  * Copyright © 2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  * Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
+ * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech>
  *
  * This file is part of GNU Mes.
  *
@@ -66,9 +67,19 @@ typedef unsigned uintmax_t;
 #include <sys/types.h>
 
 #define CHAR_BIT 8
-#define CHAR_MAX 255
+#define SCHAR_MIN (-128)
+#define SCHAR_MAX 127
 #define UCHAR_MAX 255
 
+/* Check if we are in signed or unsigned char case */
+#if '\xff' > 0
+#define CHAR_MIN 0
+#define CHAR_MAX UCHAR_MAX
+#else
+#define CHAR_MIN SCHAR_MIN
+#define CHAR_MAX SCHAR_MAX
+#endif
+
 #define INT8_MAX 127
 #define INT8_MIN (-INT8_MAX-1)
 #define UINT8_MAX 255
-- 
2.41.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]