5 /* PDCLib internal integer logic <_PDCLIB_int.h>
7 This file is part of the Public Domain C Library (PDCLib).
8 Permission is granted to use, modify, and / or redistribute at will.
11 /* -------------------------------------------------------------------------- */
12 /* You should not have to edit anything in this file; if you DO have to, it */
13 /* would be considered a bug / missing feature: notify the author(s). */
14 /* -------------------------------------------------------------------------- */
16 #ifndef _PDCLIB_CONFIG_H
17 #define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
18 #include <_PDCLIB_config.h>
22 #define _PDCLIB_AUX_H _PDCLIB_AUX_H
23 #include <_PDCLIB_aux.h>
26 /* null pointer constant */
27 #define _PDCLIB_NULL 0
29 /* -------------------------------------------------------------------------- */
30 /* Limits of native datatypes */
31 /* -------------------------------------------------------------------------- */
32 /* The definition of minimum limits for unsigned datatypes is done because */
33 /* later on we will "construct" limits for other abstract types: */
34 /* USHRT -> _PDCLIB_ + USHRT + _MIN -> _PDCLIB_USHRT_MIN -> 0 */
35 /* INT -> _PDCLIB_ + INT + _MIN -> _PDCLIB_INT_MIN -> ... you get the idea. */
36 /* -------------------------------------------------------------------------- */
38 /* Setting 'char' limits */
39 #define _PDCLIB_CHAR_BIT 8
40 #define _PDCLIB_UCHAR_MIN 0
41 #define _PDCLIB_UCHAR_MAX 0xff
42 #define _PDCLIB_SCHAR_MIN (-0x7f - 1)
43 #define _PDCLIB_SCHAR_MAX 0x7f
44 #ifdef _PDCLIB_CHAR_SIGNED
45 #define _PDCLIB_CHAR_MIN _PDCLIB_SCHAR_MIN
46 #define _PDCLIB_CHAR_MAX _PDCLIB_SCHAR_MAX
48 #define _PDCLIB_CHAR_MIN 0
49 #define _PDCLIB_CHAR_MAX _PDCLIB_UCHAR_MAX
52 /* Setting 'short' limits */
53 #if _PDCLIB_SHRT_BYTES == 2
54 #define _PDCLIB_SHRT_MAX 0x7fff
55 #define _PDCLIB_SHRT_MIN (-0x7fff - 1)
56 #define _PDCLIB_USHRT_MAX 0xffff
58 #error Unsupported width of 'short' (not 16 bit).
60 #define _PDCLIB_USHRT_MIN 0
62 #if _PDCLIB_INT_BYTES < _PDCLIB_SHRT_BYTES
63 #error Bogus setting: short > int? Check _PDCLIB_config.h.
66 /* Setting 'int' limits */
67 #if _PDCLIB_INT_BYTES == 2
68 #define _PDCLIB_INT_MAX 0x7fff
69 #define _PDCLIB_INT_MIN (-0x7fff - 1)
70 #define _PDCLIB_UINT_MAX 0xffffU
71 #elif _PDCLIB_INT_BYTES == 4
72 #define _PDCLIB_INT_MAX 0x7fffffff
73 #define _PDCLIB_INT_MIN (-0x7fffffff - 1)
74 #define _PDCLIB_UINT_MAX 0xffffffffU
75 #elif _PDCLIB_INT_BYTES == 8
76 #define _PDCLIB_INT_MAX 0x7fffffffffffffff
77 #define _PDCLIB_INT_MIN (-0x7fffffffffffffff - 1)
78 #define _PDCLIB_UINT_MAX 0xffffffffffffffff
80 #error Unsupported width of 'int' (neither 16, 32, nor 64 bit).
82 #define _PDCLIB_UINT_MIN 0
84 /* Setting 'long' limits */
85 #if _PDCLIB_LONG_BYTES == 4
86 #define _PDCLIB_LONG_MAX 0x7fffffffL
87 #define _PDCLIB_LONG_MIN (-0x7fffffffL - 1L)
88 #define _PDCLIB_ULONG_MAX 0xffffffffUL
89 #elif _PDCLIB_LONG_BYTES == 8
90 #define _PDCLIB_LONG_MAX 0x7fffffffffffffffL
91 #define _PDCLIB_LONG_MIN (-0x7fffffffffffffffL - 1L)
92 #define _PDCLIB_ULONG_MAX 0xffffffffffffffffUL
94 #error Unsupported width of 'long' (neither 32 nor 64 bit).
96 #define _PDCLIB_ULONG_MIN 0
98 /* Setting 'long long' limits */
99 #if _PDCLIB_LLONG_BYTES == 8
100 #define _PDCLIB_LLONG_MAX 0x7fffffffffffffffLL
101 #define _PDCLIB_LLONG_MIN (-0x7fffffffffffffffLL - 1LL)
102 #define _PDCLIB_ULLONG_MAX 0xffffffffffffffffULL
103 #elif _PDCLIB_LLONG_BYTES == 16
104 #define _PDCLIB_LLONG_MAX 0x7fffffffffffffffffffffffffffffffLL
105 #define _PDCLIB_LLONG_MIN (-0x7fffffffffffffffffffffffffffffffLL - 1LL)
106 #define _PDCLIB_ULLONG_MAX 0xffffffffffffffffffffffffffffffffLL
108 #error Unsupported width of 'long long' (neither 64 nor 128 bit).
110 #define _PDCLIB_ULLONG_MIN 0
112 /* -------------------------------------------------------------------------- */
113 /* <stdint.h> exact-width types and their limits */
114 /* -------------------------------------------------------------------------- */
116 /* Setting 'int8_t', its limits, and its literal. */
117 #if _PDCLIB_CHAR_BIT == 8
118 typedef signed char _PDCLIB_int8_t;
119 typedef unsigned char _PDCLIB_uint8_t;
120 #define _PDCLIB_INT8_MAX _PDCLIB_CHAR_MAX
121 #define _PDCLIB_INT8_MIN _PDCLIB_CHAR_MIN
122 #define _PDCLIB_UINT8_MAX _PDCLIB_UCHAR_MAX
123 #define _PDCLIB_INT8_LITERAL
124 #define _PDCLIB_UINT8_LITERAL
126 #error Unsupported width of char (not 8 bits).
129 /* Setting 'int16_t', its limits, and its literal */
130 #if _PDCLIB_INT_BYTES == 2
131 typedef signed int _PDCLIB_int16_t;
132 typedef unsigned int _PDCLIB_uint16_t;
133 #define _PDCLIB_INT16_MAX _PDCLIB_INT_MAX
134 #define _PDCLIB_INT16_MIN _PDCLIB_INT_MIN
135 #define _PDCLIB_UINT16_MAX _PDCLIB_UINT_MAX
136 #define _PDCLIB_INT16_LITERAL
137 #define _PDCLIB_UINT16_LITERAL
138 #elif _PDCLIB_SHRT_BYTES == 2
139 typedef signed short _PDCLIB_int16_t;
140 typedef unsigned short _PDCLIB_uint16_t;
141 #define _PDCLIB_INT16_MAX _PDCLIB_SHRT_MAX
142 #define _PDCLIB_INT16_MIN _PDCLIB_SHRT_MIN
143 #define _PDCLIB_UINT16_MAX _PDCLIB_USHRT_MAX
144 #define _PDCLIB_INT16_LITERAL s
145 #define _PDCLIB_UINT16_LITERAL us
147 #error Neither 'short' nor 'int' are 16-bit.
150 /* Setting 'int32_t', its limits, and its literal */
151 #if _PDCLIB_INT_BYTES == 4
152 typedef signed int _PDCLIB_int32_t;
153 typedef unsigned int _PDCLIB_uint32_t;
154 #define _PDCLIB_INT32_MAX _PDCLIB_INT_MAX
155 #define _PDCLIB_INT32_MIN _PDCLIB_INT_MIN
156 #define _PDCLIB_UINT32_MAX _PDCLIB_UINT_MAX
157 #define _PDCLIB_INT32_LITERAL
158 #define _PDCLIB_UINT32_LITERAL
159 #elif _PDCLIB_LONG_BYTES == 4
160 typedef signed long _PDCLIB_int32_t;
161 typedef unsigned long _PDCLIB_uint32_t;
162 #define _PDCLIB_INT32_MAX _PDCLIB_LONG_MAX
163 #define _PDCLIB_INT32_MIN _PDCLIB_LONG_MIN
164 #define _PDCLIB_UINT32_MAX _PDCLIB_LONG_MAX
165 #define _PDCLIB_INT32_LITERAL l
166 #define _PDCLIB_UINT32_LITERAL ul
168 #error Neither 'int' nor 'long' are 32-bit.
171 #if _PDCLIB_LONG_BYTES == 8
172 typedef signed long _PDCLIB_int64_t;
173 typedef unsigned long _PDCLIB_uint64_t;
174 #define _PDCLIB_INT64_MAX _PDCLIB_LONG_MAX
175 #define _PDCLIB_INT64_MIN _PDCLIB_LONG_MIN
176 #define _PDCLIB_UINT64_MAX _PDCLIB_ULONG_MAX
177 #define _PDCLIB_INT64_LITERAL l
178 #define _PDCLIB_UINT64_LITERAL ul
179 #elif _PDCLIB_LLONG_BYTES == 8
180 typedef signed long long _PDCLIB_int64_t;
181 typedef unsigned long long _PDCLIB_uint64_t;
182 #define _PDCLIB_INT64_MAX _PDCLIB_LLONG_MAX
183 #define _PDCLIB_INT64_MIN _PDCLIB_LLONG_MIN
184 #define _PDCLIB_UINT64_MAX _PDCLIB_ULLONG_MAX
185 #define _PDCLIB_INT64_LITERAL ll
186 #define _PDCLIB_UINT64_LITERAL ull
188 #error Neither 'long' nor 'long long' are 64-bit.
191 /* -------------------------------------------------------------------------- */
192 /* <stdint.h> "fastest" types and their limits */
193 /* -------------------------------------------------------------------------- */
194 /* This is, admittedly, butt-ugly. But at least it's ugly where the average */
195 /* user of PDCLib will never see it, and makes <_PDCLIB_config.h> much */
197 /* -------------------------------------------------------------------------- */
199 typedef _PDCLIB_fast8 _PDCLIB_int_fast8_t;
200 typedef unsigned _PDCLIB_fast8 _PDCLIB_uint_fast8_t;
201 #define _PDCLIB_INT_FAST8_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST8 ), _MIN )
202 #define _PDCLIB_INT_FAST8_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST8 ), _MAX )
203 #define _PDCLIB_UINT_FAST8_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST8 ), _MAX )
205 typedef _PDCLIB_fast16 _PDCLIB_int_fast16_t;
206 typedef unsigned _PDCLIB_fast16 _PDCLIB_uint_fast16_t;
207 #define _PDCLIB_INT_FAST16_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST16 ), _MIN )
208 #define _PDCLIB_INT_FAST16_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST16 ), _MAX )
209 #define _PDCLIB_UINT_FAST16_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST16 ), _MAX )
211 typedef _PDCLIB_fast32 _PDCLIB_int_fast32_t;
212 typedef unsigned _PDCLIB_fast32 _PDCLIB_uint_fast32_t;
213 #define _PDCLIB_INT_FAST32_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST32 ), _MIN )
214 #define _PDCLIB_INT_FAST32_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST32 ), _MAX )
215 #define _PDCLIB_UINT_FAST32_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST32 ), _MAX )
217 typedef _PDCLIB_fast64 _PDCLIB_int_fast64_t;
218 typedef unsigned _PDCLIB_fast64 _PDCLIB_uint_fast64_t;
219 #define _PDCLIB_INT_FAST64_MIN concat( concat( _PDCLIB_, _PDCLIB_FAST64 ), _MIN )
220 #define _PDCLIB_INT_FAST64_MAX concat( concat( _PDCLIB_, _PDCLIB_FAST64 ), _MAX )
221 #define _PDCLIB_UINT_FAST64_MAX concat( concat( _PDCLIB_U, _PDCLIB_FAST64 ), _MAX )
223 /* -------------------------------------------------------------------------- */
224 /* Various <stddef.h> typedefs and limits */
225 /* -------------------------------------------------------------------------- */
227 typedef _PDCLIB_ptrdiff _PDCLIB_ptrdiff_t;
228 #define _PDCLIB_PTRDIFF_MIN concat( concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MIN )
229 #define _PDCLIB_PTRDIFF_MAX concat( concat( _PDCLIB_, _PDCLIB_PTRDIFF ), _MAX )
231 #define _PDCLIB_SIG_ATOMIC_MIN concat( concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MIN )
232 #define _PDCLIB_SIG_ATOMIC_MAX concat( concat( _PDCLIB_, _PDCLIB_SIG_ATOMIC ), _MAX )
234 typedef _PDCLIB_size _PDCLIB_size_t;
235 #define _PDCLIB_SIZE_MAX concat( concat( _PDCLIB_, _PDCLIB_SIZE ), _MAX )
237 typedef _PDCLIB_wchar _PDCLIB_wchar_t;
238 #define _PDCLIB_WCHAR_MIN concat( concat( _PDCLIB_, _PDCLIB_WCHAR ), _MIN )
239 #define _PDCLIB_WCHAR_MAX concat( concat( _PDCLIB_, _PDCLIB_WCHAR ), _MAX )
241 typedef _PDCLIB_intptr _PDCLIB_intptr_t;
242 typedef unsigned _PDCLIB_intptr _PDCLIB_uintptr_t;
243 #define _PDCLIB_INTPTR_MIN concat( concat( _PDCLIB_, _PDCLIB_INTPTR ), _MIN )
244 #define _PDCLIB_INTPTR_MAX concat( concat( _PDCLIB_, _PDCLIB_INTPTR ), _MAX )
245 #define _PDCLIB_UINTPTR_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTPTR ), _MAX )
247 typedef _PDCLIB_intmax _PDCLIB_intmax_t;
248 typedef unsigned _PDCLIB_intmax _PDCLIB_uintmax_t;
249 #define _PDCLIB_INTMAX_MIN concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MIN )
250 #define _PDCLIB_INTMAX_MAX concat( concat( _PDCLIB_, _PDCLIB_INTMAX ), _MAX )
251 #define _PDCLIB_UINTMAX_MAX concat( concat( _PDCLIB_U, _PDCLIB_INTMAX ), _MAX )
252 #define _PDCLIB_INTMAX_C( value ) concat( value, _PDCLIB_INTMAX_LITERAL )
253 #define _PDCLIB_UINTMAX_C( value ) concat( value, concat( u, _PDCLIB_INTMAX_LITERAL ) )