From c5b0889ccb64e6fc8aaa7c70bff8c30efb4efdde Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 16 Oct 2015 22:25:28 +0200 Subject: the compiler determines how wchar is implement + intconf.h contains the signess of char MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- gen/bits/intconf.c | 20 ++++++++++++++++++++ gen/bits/intconf.h | 13 +++++++++++++ 2 files changed, 33 insertions(+) (limited to 'gen') 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 #include +#include #include +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) -- cgit v1.2.3-70-g09d2