turns out using long long for 64 bits was a bad idea

This commit is contained in:
bumbread 2022-08-01 09:02:36 +11:00
parent 4bcbcbff50
commit c65efc8239
3 changed files with 263 additions and 155 deletions

View File

@ -5,161 +5,256 @@
#include <limits.h>
#include <wchar.h>
#define PRId8 "hhd"
#define PRId16 "hd"
#define PRId32 "d"
#define PRId64 "lld"
#define PRIdFAST8 "d"
#define PRIdFAST16 "d"
#define PRIdFAST32 "d"
#define PRIdFAST64 "lld"
#define PRIdLEAST8 "hhd"
#define PRIdLEAST16 "hd"
#define PRIdLEAST32 "d"
#define PRIdLEAST64 "lld"
#define PRIdPTR "lld"
#define PRIdMAX "lld"
#define PRIi8 "hhi"
#define PRIi16 "hi"
#define PRIi32 "i"
#define PRIi64 "lli"
#define PRIiFAST8 "i"
#define PRIiFAST16 "i"
#define PRIiFAST32 "i"
#define PRIiFAST64 "lli"
#define PRIiLEAST8 "hhi"
#define PRIiLEAST16 "hi"
#define PRIiLEAST32 "i"
#define PRIiLEAST64 "lli"
#define PRIiPTR "lli"
#define PRIiMAX "lli"
#define PRIo8 "hho"
#define PRIo16 "ho"
#define PRIo32 "o"
#define PRIo64 "llo"
#define PRIoLEAST8 "hho"
#define PRIoLEAST16 "ho"
#define PRIoLEAST32 "o"
#define PRIoLEAST64 "llo"
#define PRIoFAST8 "o"
#define PRIoFAST16 "o"
#define PRIoFAST32 "o"
#define PRIoFAST64 "llo"
#define PRIoPTR "llo"
#define PRIoMAX "llo"
#define PRIu8 "hhu"
#define PRIu16 "hu"
#define PRIu32 "u"
#define PRIu64 "llu"
#define PRIuLEAST8 "hhu"
#define PRIuLEAST16 "hu"
#define PRIuLEAST32 "u"
#define PRIuLEAST64 "llu"
#define PRIuFAST8 "u"
#define PRIuFAST16 "u"
#define PRIuFAST32 "u"
#define PRIuFAST64 "llu"
#define PRIuPTR "llu"
#define PRIuMAX "llu"
#define PRIo8 "hho"
#define PRId8 "hhd"
#define PRIx8 "hhx"
#define PRIx16 "hx"
#define PRIx32 "x"
#define PRIx64 "llx"
#define PRIxLEAST8 "hhx"
#define PRIxLEAST16 "hx"
#define PRIxLEAST32 "x"
#define PRIxLEAST64 "llx"
#define PRIxFAST8 "x"
#define PRIxFAST16 "x"
#define PRIxFAST32 "x"
#define PRIxFAST64 "llx"
#define PRIxPTR "llx"
#define PRIxMAX "llx"
#define PRIX8 "hhX"
#define PRIX16 "hX"
#define PRIX32 "X"
#define PRIX64 "llX"
#define PRIXLEAST8 "hhX"
#define PRIXLEAST16 "hX"
#define PRIXLEAST32 "X"
#define PRIXLEAST64 "llX"
#define PRIXFAST8 "X"
#define PRIXFAST16 "X"
#define PRIXFAST32 "X"
#define PRIXFAST64 "llX"
#define PRIXPTR "llX"
#define PRIXMAX "llX"
#define SCNd8 "hhd"
#define SCNd16 "hd"
#define SCNd32 "d"
#define SCNd64 "lld"
#define SCNdFAST8 "d"
#define SCNdFAST16 "d"
#define SCNdFAST32 "d"
#define SCNdFAST64 "lld"
#define SCNdLEAST8 "hhd"
#define SCNdLEAST16 "hd"
#define SCNdLEAST32 "d"
#define SCNdLEAST64 "lld"
#define SCNdPTR "lld"
#define SCNdMAX "lld"
#define PRIi16 "hi"
#define PRIu16 "hu"
#define PRIo16 "ho"
#define PRId16 "hd"
#define PRIx16 "hx"
#define PRIX16 "hX"
#define PRIi32 "i"
#define PRIu32 "u"
#define PRIo32 "o"
#define PRId32 "d"
#define PRIx32 "x"
#define PRIX32 "X"
#if defined(_WIN64)
#define PRIi64 "lli"
#define PRIu64 "llu"
#define PRIo64 "llo"
#define PRId64 "lld"
#define PRIx64 "llx"
#define PRIX64 "llX"
#else
#define PRIi64 "li"
#define PRIu64 "lu"
#define PRIo64 "lo"
#define PRId64 "ld"
#define PRIx64 "lx"
#define PRIX64 "lX"
#endif
#define PRIdLEAST8 "hhi"
#define PRIuLEAST8 "hhu"
#define PRIoLEAST8 "hho"
#define PRIiLEAST8 "hhd"
#define PRIxLEAST8 "hhx"
#define PRIXLEAST8 "hhX"
#define PRIiLEAST16 "hi"
#define PRIuLEAST16 "hu"
#define PRIoLEAST16 "ho"
#define PRIdLEAST16 "hd"
#define PRIxLEAST16 "hx"
#define PRIXLEAST16 "hX"
#define PRIiLEAST32 "i"
#define PRIuLEAST32 "u"
#define PRIoLEAST32 "o"
#define PRIdLEAST32 "d"
#define PRIxLEAST32 "x"
#define PRIXLEAST32 "X"
#if defined(_WIN32)
#define PRIiLEAST64 "lli"
#define PRIuLEAST64 "llu"
#define PRIoLEAST64 "llo"
#define PRIdLEAST64 "lld"
#define PRIxLEAST64 "llx"
#define PRIXLEAST64 "llX"
#else
#define PRIiLEAST64 "li"
#define PRIuLEAST64 "lu"
#define PRIoLEAST64 "lo"
#define PRIdLEAST64 "ld"
#define PRIxLEAST64 "lx"
#define PRIXLEAST64 "lX"
#endif
#define PRIiFAST8 "i"
#define PRIuFAST8 "u"
#define PRIoFAST8 "o"
#define PRIdFAST8 "d"
#define PRIxFAST8 "x"
#define PRIXFAST8 "X"
#define PRIiFAST16 "i"
#define PRIuFAST16 "u"
#define PRIoFAST16 "o"
#define PRIdFAST16 "d"
#define PRIxFAST16 "x"
#define PRIXFAST16 "X"
#define PRIiFAST32 "i"
#define PRIuFAST32 "u"
#define PRIoFAST32 "o"
#define PRIdFAST32 "d"
#define PRIxFAST32 "x"
#define PRIXFAST32 "X"
#if defined(_WIN32)
#define PRIiFAST64 "lli"
#define PRIuFAST64 "llu"
#define PRIoFAST64 "llo"
#define PRIdFAST64 "lld"
#define PRIxFAST64 "llx"
#define PRIXFAST64 "llX"
#define PRIiPTR "lli"
#define PRIuPTR "llu"
#define PRIoPTR "llo"
#define PRIdPTR "lld"
#define PRIxPTR "llx"
#define PRIXPTR "llX"
#define PRIiMAX "lli"
#define PRIuMAX "llu"
#define PRIoMAX "llo"
#define PRIdMAX "lld"
#define PRIxMAX "llx"
#define PRIXMAX "llX"
#else
#define PRIiFAST64 "li"
#define PRIuFAST64 "lu"
#define PRIoFAST64 "lo"
#define PRIdFAST64 "ld"
#define PRIxFAST64 "lx"
#define PRIXFAST64 "lX"
#define PRIiPTR "li"
#define PRIuPTR "lu"
#define PRIoPTR "lo"
#define PRIdPTR "ld"
#define PRIxPTR "lx"
#define PRIXPTR "lX"
#define PRIiMAX "li"
#define PRIuMAX "lu"
#define PRIoMAX "lo"
#define PRIdMAX "ld"
#define PRIxMAX "lx"
#define PRIXMAX "lX"
#endif
#define SCNi8 "hhi"
#define SCNi16 "hi"
#define SCNi32 "i"
#define SCNi64 "lli"
#define SCNiFAST8 "i"
#define SCNiFAST16 "i"
#define SCNiFAST32 "i"
#define SCNiFAST64 "lli"
#define SCNiLEAST8 "hhi"
#define SCNiLEAST16 "hi"
#define SCNiLEAST32 "i"
#define SCNiLEAST64 "lli"
#define SCNiPTR "lli"
#define SCNiMAX "lli"
#define SCNo8 "hho"
#define SCNo16 "ho"
#define SCNo32 "o"
#define SCNo64 "llo"
#define SCNoLEAST8 "hho"
#define SCNoLEAST16 "ho"
#define SCNoLEAST32 "o"
#define SCNoLEAST64 "llo"
#define SCNoFAST8 "o"
#define SCNoFAST16 "o"
#define SCNoFAST32 "o"
#define SCNoFAST64 "llo"
#define SCNoPTR "llo"
#define SCNoMAX "llo"
#define SCNu8 "hhu"
#define SCNu16 "hu"
#define SCNu32 "u"
#define SCNu64 "llu"
#define SCNuLEAST8 "hhu"
#define SCNuLEAST16 "hu"
#define SCNuLEAST32 "u"
#define SCNuLEAST64 "llu"
#define SCNuFAST8 "u"
#define SCNuFAST16 "u"
#define SCNuFAST32 "u"
#define SCNuFAST64 "llu"
#define SCNuPTR "llu"
#define SCNuMAX "llu"
#define SCNo8 "hho"
#define SCNd8 "hhd"
#define SCNx8 "hhx"
#define SCNx16 "hx"
#define SCNx32 "x"
#define SCNx64 "llx"
#define SCNiLEAST8 "hhi"
#define SCNuLEAST8 "hhu"
#define SCNoLEAST8 "hho"
#define SCNdLEAST8 "hhd"
#define SCNxLEAST8 "hhx"
#define SCNdFAST8 "hhd"
#define SCNiFAST8 "hhi"
#define SCNoFAST8 "hho"
#define SCNuFAST8 "hhu"
#define SCNxFAST8 "hhx"
#define SCNi16 "hi"
#define SCNu16 "hu"
#define SCNo16 "ho"
#define SCNd16 "hd"
#define SCNx16 "hx"
#define SCNiLEAST16 "hi"
#define SCNuLEAST16 "hu"
#define SCNoLEAST16 "ho"
#define SCNdLEAST16 "hd"
#define SCNxLEAST16 "hx"
#define SCNxLEAST32 "x"
#define SCNxLEAST64 "llx"
#define SCNxFAST8 "x"
#define SCNiFAST16 "i"
#define SCNuFAST16 "u"
#define SCNoFAST16 "o"
#define SCNdFAST16 "d"
#define SCNxFAST16 "x"
#define SCNi32 "i"
#define SCNu32 "u"
#define SCNo32 "o"
#define SCNd32 "d"
#define SCNx32 "x"
#define SCNiFAST32 "i"
#define SCNuFAST32 "u"
#define SCNoFAST32 "o"
#define SCNdFAST32 "d"
#define SCNxFAST32 "x"
#define SCNxFAST64 "llx"
#define SCNxPTR "llx"
#define SCNxMAX "llx"
#define SCNiLEAST32 "i"
#define SCNuLEAST32 "u"
#define SCNoLEAST32 "o"
#define SCNdLEAST32 "d"
#define SCNxLEAST32 "x"
#if defined(_WIN32)
#define SCNi64 "lli"
#define SCNu64 "llu"
#define SCNo64 "llo"
#define SCNd64 "lld"
#define SCNx64 "llx"
#define SCNiLEAST64 "lli"
#define SCNuLEAST64 "llu"
#define SCNoLEAST64 "llo"
#define SCNdLEAST64 "lld"
#define SCNxLEAST64 "llx"
#define SCNiFAST64 "lli"
#define SCNuFAST64 "llu"
#define SCNoFAST64 "llo"
#define SCNdFAST64 "lld"
#define SCNxFAST64 "llx"
#define SCNiMAX "lli"
#define SCNuMAX "llu"
#define SCNoMAX "llo"
#define SCNdMAX "lld"
#define SCNxMAX "llx"
#define SCNiPTR "lli"
#define SCNuPTR "llu"
#define SCNoPTR "llo"
#define SCNdPTR "lld"
#define SCNxPTR "llx"
#else
#define SCNi64 "li"
#define SCNu64 "lu"
#define SCNo64 "lo"
#define SCNd64 "ld"
#define SCNx64 "lx"
#define SCNiLEAST64 "li"
#define SCNuLEAST64 "lu"
#define SCNoLEAST64 "lo"
#define SCNdLEAST64 "ld"
#define SCNxLEAST64 "lx"
#define SCNiFAST64 "li"
#define SCNuFAST64 "lu"
#define SCNoFAST64 "lo"
#define SCNdFAST64 "ld"
#define SCNxFAST64 "lx"
#define SCNiMAX "li"
#define SCNuMAX "lu"
#define SCNoMAX "lo"
#define SCNdMAX "ld"
#define SCNxMAX "lx"
#define SCNiPTR "li"
#define SCNuPTR "lu"
#define SCNoPTR "lo"
#define SCNdPTR "ld"
#define SCNxPTR "lx"
#endif
typedef struct imaxdiv_t imaxdiv_t;
struct imaxdiv_t {

View File

@ -7,9 +7,9 @@
#define _ILP64 3
#define _SILP64 4
#if defined(__linux__)
#if defined()
#define _DATA_MODEL _LP64
#elif defined(_WIN64)
#elif defined()
#define _DATA_MODEL _LLP64
#else
#error "Could not determine target OS"
@ -46,18 +46,18 @@
#define INT_MIN -0x80000000
#define INT_MAX +0x7fffffff
#if _DATA_MODEL == _LP64
#define ULONG_WIDTH 64
#define LONG_WIDTH 64
#define ULONG_MAX 0xffffffffffffffffull
#define LONG_MIN -0x8000000000000000ll
#define LONG_MAX +0x7fffffffffffffffll
#elif _DATA_MODEL == _LLP64
#if defined(_WIN64)
#define ULONG_WIDTH 32
#define LONG_WIDTH 32
#define ULONG_MAX +0xffffffff
#define LONG_MIN -0x80000000
#define LONG_MAX +0x7fffffff
#else
#define ULONG_WIDTH 64
#define LONG_WIDTH 64
#define ULONG_MAX 0xffffffffffffffffull
#define LONG_MIN -0x8000000000000000ll
#define LONG_MAX +0x7fffffffffffffffll
#endif
#define ULLONG_WIDTH 64

View File

@ -8,7 +8,12 @@ typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#defined (_WIN64)
typedef unsigned long long uint64_t;
#else
typedef unsigned long uint64_t;
#endif
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
@ -124,9 +129,17 @@ typedef uint64_t uintmax_t;
#define INT8_C(lit) lit
#define INT16_C(lit) lit
#define INT32_C(lit) lit
#define INT64_C(lit) lit ## ll
#if defined(_WIN32)
#define INT64_C(lit) lit ## ll
#else
#define INT64_C(lit) lit # l
#endif
#define UINT8_C(lit) lit
#define UINT16_C(lit) lit
#define UINT32_C(lit) lit
#define UINT64_C(lit) lit ## ull
#if defined(_WIN32)
#define UINT64_C(lit) lit ## ull
#endif