kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

limits.h (1632B)


      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 MB_LEN_MAX 1 /* freestanding has no locale; smallest legal value */
     18 
     19 /* signed / unsigned char */
     20 #define SCHAR_MAX 127
     21 #define SCHAR_MIN (-128)
     22 #define UCHAR_MAX 255
     23 
     24 /* plain char -- signedness is implementation-defined and set by the
     25    compiler/ABI; a header cannot change it. We report what the compiler
     26    chose. -funsigned-char / -fsigned-char flip __CHAR_UNSIGNED__. */
     27 #ifdef __CHAR_UNSIGNED__
     28 #define CHAR_MIN 0
     29 #define CHAR_MAX 255
     30 #else
     31 #define CHAR_MIN (-128)
     32 #define CHAR_MAX 127
     33 #endif
     34 
     35 /* short / unsigned short */
     36 #define SHRT_MAX 32767
     37 #define SHRT_MIN (-32768)
     38 #define USHRT_MAX 65535
     39 
     40 /* int / unsigned int */
     41 #define INT_MAX 2147483647
     42 #define INT_MIN (-INT_MAX - 1)
     43 #define UINT_MAX 4294967295U
     44 
     45 /* long / unsigned long -- LP64 (Unix 64-bit) makes long 64-bit, while
     46    LLP64 (Windows 64-bit) and ILP32 keep it 32-bit. Genuinely varying. */
     47 #define LONG_MAX __LONG_MAX__
     48 #define LONG_MIN (-LONG_MAX - 1L)
     49 #define ULONG_MAX (LONG_MAX * 2UL + 1UL)
     50 
     51 /* long long / unsigned long long */
     52 #define LLONG_MAX 9223372036854775807LL
     53 #define LLONG_MIN (-LLONG_MAX - 1LL)
     54 #define ULLONG_MAX 18446744073709551615ULL
     55 
     56 #endif