aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--gen/bits/intconf.c20
-rw-r--r--gen/bits/intconf.h13
-rw-r--r--include/bits/types.h20
-rw-r--r--include/wchar.h12
4 files changed, 62 insertions, 3 deletions
diff --git a/gen/bits/intconf.c b/gen/bits/intconf.c
index 2ba2754..8d1311b 100644
--- a/gen/bits/intconf.c
+++ b/gen/bits/intconf.c
@@ -17,10 +17,16 @@
*/
#include <stdio.h>
#include <string.h>
+#include <stddef.h>
#include <time.h>
+volatile char nul = 0;
+volatile wchar_t wnul = 0;
+
+
+
/**
* On my amd64 machine, the usual result is:
* int_fast8_t = int32_t
@@ -109,6 +115,7 @@ int main(int argc, char* argv[])
r |= printf("LONG_BIT %zu\n", 8 * sizeof(long int));
r |= printf("LONG_LONG_BIT %zu\n", 8 * sizeof(long long int));
r |= printf("PTR_BIT %zu\n", 8 * sizeof(void*));
+ r |= printf("WCHAR_BIT %zu\n", 8 * sizeof(L'\0'));
r |= printf("INT%zu %s\n", 8 * sizeof(char), "char");
r |= printf("INT%zu %s\n", 8 * sizeof(short int), "short int");
@@ -123,6 +130,19 @@ int main(int argc, char* argv[])
else if (!strcmp(argv[1], "fast16")) r = fast(16);
else if (!strcmp(argv[1], "fast32")) r = fast(32);
else if (!strcmp(argv[1], "fast64")) r = fast(64);
+ else if (!strcmp(argv[1], "char-signed"))
+ {
+ nul = ~nul;
+ r = !(nul > 0);
+ return printf("%i\n", r) < 0 ? 1 : 0;
+ }
+ else if (!strcmp(argv[1], "wchar-signed"))
+ {
+ wnul = ~wnul;
+ r = !(wnul > 0);
+ return printf("%i\n", r) < 0 ? 1 : 0;
+ }
+
if (r <= 0)
return 1;
return printf("%i\n", r) < 0 ? 1 : 0;
diff --git a/gen/bits/intconf.h b/gen/bits/intconf.h
index eb7b5b5..f9ff861 100644
--- a/gen/bits/intconf.h
+++ b/gen/bits/intconf.h
@@ -25,12 +25,25 @@
//>FAST64=$(bin/gen/bits/intconf fast64)
#define __MAX_TO_MIN(max) (-(max) - 1)
+#if //(bin/gen/bits/intconf char-signed)
+# define __CHAR_SIGNED
+# define __CHAR_SIGNESS signed
+#endif
+# define __CHAR_SIGNESS unsigned
+#endif
+#if //(bin/gen/bits/intconf wchar-signed)
+# define __WCHAR_SIGNED
+# define __WCHAR_SIGNESS signed
+#else
+# define __WCHAR_SIGNESS unsigned
+#endif
#define __CHAR_BIT //(bin/gen/bits/intconf | grep ^CHAR_BIT | sed "s/^[^ ]* //")
#define __SHORT_BIT //(bin/gen/bits/intconf | grep ^SHORT_BIT | sed "s/^[^ ]* //")
#define __INT_BIT //(bin/gen/bits/intconf | grep ^INT_BIT | sed "s/^[^ ]* //")
#define __LONG_BIT //(bin/gen/bits/intconf | grep ^LONG_BIT | sed "s/^[^ ]* //")
#define __LONG_LONG_BIT //(bin/gen/bits/intconf | grep ^LONG_LONG_BIT | sed "s/^[^ ]* //")
#define __PTR_BIT //(bin/gen/bits/intconf | grep ^PTR_BIT | sed "s/^[^ ]* //")
+#define __WCHAR_BIT //(bin/gen/bits/intconf | grep ^WCHAR_BIT | sed "s/^[^ ]* //")
#define __INT8 //(bin/gen/bits/intconf | grep ^INT8 | sed "s/^[^ ]* //" | sed 1q)
#define __INT16 //(bin/gen/bits/intconf | grep ^INT16 | sed "s/^[^ ]* //" | sed 1q)
#define __INT32 //(bin/gen/bits/intconf | grep ^INT32 | sed "s/^[^ ]* //" | sed 1q)
diff --git a/include/bits/types.h b/include/bits/types.h
index dfaef5d..f2318c1 100644
--- a/include/bits/types.h
+++ b/include/bits/types.h
@@ -94,11 +94,27 @@ typedef unsigned __LIMITED_PTR_INT uptrdiff_t;
*/
# if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t)
# define __DEFINED_wchar_t
-typedef long int wchar_t
+# if __WCHAR_BIT == 8
+typedef __WCHAR_SIGNESS __INT8 wchar_t
+# elif __WCHAR_BIT == 16
+typedef __WCHAR_SIGNESS __INT16 wchar_t
+# elif __WCHAR_BIT == 32
+typedef __WCHAR_SIGNESS __INT32 wchar_t
+# elif __WCHAR_BIT == 64
+typedef __WCHAR_SIGNESS __INT64 wchar_t
+# endif
__warning("'wchar_t' is not guaranteed to be defined as expected, use 'int32_t'.");
# endif
# ifndef __WCHAR_MAX
-# define __WCHAR_MAX INTPTR_MAX
+# if __WCHAR_BIT == 8
+# define __WCHAR_MAX INT8_MAX
+# elif __WCHAR_BIT == 16
+# define __WCHAR_MAX INT16_MAX
+# elif __WCHAR_BIT == 32
+# define __WCHAR_MAX INT32_MAX
+# elif __WCHAR_BIT == 64
+# define __WCHAR_MAX INT64_MAX
+# endif
# endif
diff --git a/include/wchar.h b/include/wchar.h
index aade683..4437e6d 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -42,7 +42,17 @@
* End of a wide-character stream
*/
#ifndef WEOF
-# define WEOF -1L
+# if __WCHAR_BIT == __CHAR_BIT
+# define WEOF -1
+# elif __WCHAR_BIT == __SHORT_BIT
+# define WEOF -1
+# elif __WCHAR_BIT == __INT_BIT
+# define WEOF -1
+# elif __WCHAR_BIT == __LONG_BIT
+# define WEOF -1L
+# else
+# define WEOF -1LL
+# endif
#endif