limits.h (1950B)
1 /* limits.h -- C11 7.10 -- Sizes of integer types 2 * 3 * kit assumes a target where: 4 * - CHAR_BIT == 8 5 * - short == 16 bits 6 * - int == 32 bits 7 * - long long == 64 bits 8 * - two's complement representation 9 * These hold on every modern C11 target we care about. The signedness of 10 * plain `char` and the width of `long` genuinely differ across targets and 11 * are still derived from compiler-predefined macros. 12 */ 13 #ifndef KIT_LIMITS_H 14 #define KIT_LIMITS_H 15 16 #define CHAR_BIT 8 17 #define BOOL_WIDTH 1 18 #define CHAR_WIDTH 8 19 #define SCHAR_WIDTH 8 20 #define UCHAR_WIDTH 8 21 #define SHRT_WIDTH 16 22 #define USHRT_WIDTH 16 23 #define INT_WIDTH 32 24 #define UINT_WIDTH 32 25 #define LONG_WIDTH (__SIZEOF_LONG__ * CHAR_BIT) 26 #define ULONG_WIDTH (__SIZEOF_LONG__ * CHAR_BIT) 27 #define LLONG_WIDTH 64 28 #define ULLONG_WIDTH 64 29 #define MB_LEN_MAX 1 /* freestanding has no locale; smallest legal value */ 30 31 /* signed / unsigned char */ 32 #define SCHAR_MAX 127 33 #define SCHAR_MIN (-128) 34 #define UCHAR_MAX 255 35 36 /* plain char -- signedness is implementation-defined and set by the 37 compiler/ABI; a header cannot change it. We report what the compiler 38 chose. -funsigned-char / -fsigned-char flip __CHAR_UNSIGNED__. */ 39 #ifdef __CHAR_UNSIGNED__ 40 #define CHAR_MIN 0 41 #define CHAR_MAX 255 42 #else 43 #define CHAR_MIN (-128) 44 #define CHAR_MAX 127 45 #endif 46 47 /* short / unsigned short */ 48 #define SHRT_MAX 32767 49 #define SHRT_MIN (-32768) 50 #define USHRT_MAX 65535 51 52 /* int / unsigned int */ 53 #define INT_MAX 2147483647 54 #define INT_MIN (-INT_MAX - 1) 55 #define UINT_MAX 4294967295U 56 57 /* long / unsigned long -- LP64 (Unix 64-bit) makes long 64-bit, while 58 LLP64 (Windows 64-bit) and ILP32 keep it 32-bit. Genuinely varying. */ 59 #define LONG_MAX __LONG_MAX__ 60 #define LONG_MIN (-LONG_MAX - 1L) 61 #define ULONG_MAX (LONG_MAX * 2UL + 1UL) 62 63 /* long long / unsigned long long */ 64 #define LLONG_MAX 9223372036854775807LL 65 #define LLONG_MIN (-LLONG_MAX - 1LL) 66 #define ULLONG_MAX 18446744073709551615ULL 67 68 #endif