MRPT  1.9.9
xSens_MT4/xstypes/include/xsens/pstdint.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef _PSTDINT_H_INCLUDED
11 #include <stddef.h>
12 #include <limits.h>
13 
14 /*
15  * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
16  * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
17  */
18 
19 #if ( \
20  defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && \
21  __STDC_VERSION__ >= 199901L) || \
22  (defined(__WATCOMC__) && __WATCOMC__ >= 1250) || \
23  (defined(__GNUC__) && __GNUC__ > 2) || \
24  (defined(_MSC_VER) && _MSC_VER >= 1600) || defined(IAR_ARM_CM3) || \
25  (defined(__ICCARM__) && __ICCARM__) || \
26  (defined(_ADI_COMPILER) && _ADI_COMPILER) || \
27  (defined(__ICC8051__) && __ICC8051__)
28 #include <stdint.h>
29 #endif
30 
31 #if ( \
32  defined(_STDINT_H_INCLUDED) || defined(_STDINT) || defined(_STDINT_H) || \
33  defined(_STDINT_H_) || defined(BOOST_CSTDINT_HPP)) && \
34  !defined(_PSTDINT_H_INCLUDED)
35 #define _PSTDINT_H_INCLUDED
36 #ifndef PRINTF_INT64_MODIFIER
37 #if (__WORDSIZE == 64) && !defined(__APPLE__) // lint !e553 __WORDSIZE should
38 // always be defined at this
39 // point
40 #define PRINTF_INT64_MODIFIER "l"
41 #else
42 #define PRINTF_INT64_MODIFIER "ll"
43 #endif
44 #endif
45 #ifndef PRINTF_INT32_MODIFIER
46 /* There might be cases where this needs to be "l". */
47 #define PRINTF_INT32_MODIFIER ""
48 #endif
49 #ifndef PRINTF_INT16_MODIFIER
50 #define PRINTF_INT16_MODIFIER "h"
51 #endif
52 #ifndef PRINTF_INTMAX_MODIFIER
53 #define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
54 #endif
55 #ifndef PRINTF_INT64_HEX_WIDTH
56 #define PRINTF_INT64_HEX_WIDTH "16"
57 #endif
58 #ifndef PRINTF_INT32_HEX_WIDTH
59 #define PRINTF_INT32_HEX_WIDTH "8"
60 #endif
61 #ifndef PRINTF_INT16_HEX_WIDTH
62 #define PRINTF_INT16_HEX_WIDTH "4"
63 #endif
64 #ifndef PRINTF_INT8_HEX_WIDTH
65 #define PRINTF_INT8_HEX_WIDTH "2"
66 #endif
67 #ifndef PRINTF_INT64_DEC_WIDTH
68 #define PRINTF_INT64_DEC_WIDTH "20"
69 #endif
70 #ifndef PRINTF_INT32_DEC_WIDTH
71 #define PRINTF_INT32_DEC_WIDTH "10"
72 #endif
73 #ifndef PRINTF_INT16_DEC_WIDTH
74 #define PRINTF_INT16_DEC_WIDTH "5"
75 #endif
76 #ifndef PRINTF_INT8_DEC_WIDTH
77 #define PRINTF_INT8_DEC_WIDTH "3"
78 #endif
79 #ifndef PRINTF_INTMAX_HEX_WIDTH
80 #define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
81 #endif
82 #ifndef PRINTF_INTMAX_DEC_WIDTH
83 #define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
84 #endif
85 
86 /*
87  * Something really weird is going on with Open Watcom. Just pull some of
88  * these duplicated definitions from Open Watcom's stdint.h file for now.
89  */
90 
91 #if defined(__WATCOMC__) && __WATCOMC__ >= 1250
92 #if !defined(INT64_C)
93 #define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
94 #endif
95 #if !defined(UINT64_C)
96 #define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
97 #endif
98 #if !defined(INT32_C)
99 #define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
100 #endif
101 #if !defined(UINT32_C)
102 #define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
103 #endif
104 #if !defined(INT16_C)
105 #define INT16_C(x) (x)
106 #endif
107 #if !defined(UINT16_C)
108 #define UINT16_C(x) (x)
109 #endif
110 #if !defined(INT8_C)
111 #define INT8_C(x) (x)
112 #endif
113 #if !defined(UINT8_C)
114 #define UINT8_C(x) (x)
115 #endif
116 #if !defined(UINT64_MAX)
117 #define UINT64_MAX 18446744073709551615ULL
118 #endif
119 #if !defined(INT64_MAX)
120 #define INT64_MAX 9223372036854775807LL
121 #endif
122 #if !defined(UINT32_MAX)
123 #define UINT32_MAX 4294967295UL
124 #endif
125 #if !defined(INT32_MAX)
126 #define INT32_MAX 2147483647L
127 #endif
128 #if !defined(INTMAX_MAX)
129 #define INTMAX_MAX INT64_MAX
130 #endif
131 #if !defined(INTMAX_MIN)
132 #define INTMAX_MIN INT64_MIN
133 #endif
134 #endif
135 
136 /* Some of the targets compiled by Visual Dsp++ (like the Sharc) do not have a
137  notion of 8bit of 16bit value
138  We define these here although the actual storage size is 32 bits
139 */
140 #if (defined(_ADI_COMPILER) && _ADI_COMPILER)
141 #ifndef int8_t
142 typedef signed char int8_t;
143 #endif
144 #ifndef uint8_t
145 typedef unsigned char uint8_t;
146 #endif
147 #ifndef int16_t
148 typedef signed short int16_t;
149 #endif
150 #ifndef uint16_t
151 typedef unsigned short uint16_t;
152 #endif
153 #endif //(defined(_ADI_COMPILER) && _ADI_COMPILER)
154 
155 #endif
156 
157 #ifndef _PSTDINT_H_INCLUDED
158 #define _PSTDINT_H_INCLUDED
159 
160 #ifndef SIZE_MAX
161 #ifdef DOXYGEN
162 #define SIZE_MAX (~0)
163 #else
164 #define SIZE_MAX (~(size_t)0)
165 #endif
166 #endif
167 
168 /*
169  * Deduce the type assignments from limits.h under the assumption that
170  * integer sizes in bits are powers of 2, and follow the ANSI
171  * definitions.
172  */
173 
174 #ifndef UINT8_MAX
175 #define UINT8_MAX 0xff
176 #endif
177 #ifndef uint8_t
178 #if (UCHAR_MAX == UINT8_MAX) || defined(S_SPLINT_S)
179 typedef unsigned char uint8_t;
180 #define UINT8_C(v) ((uint8_t)v)
181 #else
182 #error "Platform not supported"
183 #endif
184 #endif
185 
186 #ifndef INT8_MAX
187 #define INT8_MAX 0x7f
188 #endif
189 #ifndef INT8_MIN
190 #define INT8_MIN INT8_C(0x80)
191 #endif
192 #ifndef int8_t
193 #if (SCHAR_MAX == INT8_MAX) || defined(S_SPLINT_S)
194 typedef signed char int8_t;
195 #define INT8_C(v) ((int8_t)v)
196 #else
197 #error "Platform not supported"
198 #endif
199 #endif
200 
201 #ifndef UINT16_MAX
202 #define UINT16_MAX 0xffff
203 #endif
204 #ifndef uint16_t
205 #if (UINT_MAX == UINT16_MAX) || defined(S_SPLINT_S)
206 typedef unsigned int uint16_t;
207 #ifndef PRINTF_INT16_MODIFIER
208 #define PRINTF_INT16_MODIFIER ""
209 #endif
210 #define UINT16_C(v) ((uint16_t)(v))
211 #elif (USHRT_MAX == UINT16_MAX)
212 typedef unsigned short uint16_t;
213 #define UINT16_C(v) ((uint16_t)(v))
214 #ifndef PRINTF_INT16_MODIFIER
215 #define PRINTF_INT16_MODIFIER "h"
216 #endif
217 #else
218 #error "Platform not supported"
219 #endif
220 #endif
221 
222 #ifndef INT16_MAX
223 #define INT16_MAX 0x7fff
224 #endif
225 #ifndef INT16_MIN
226 #define INT16_MIN INT16_C(0x8000)
227 #endif
228 #ifndef int16_t
229 #if (INT_MAX == INT16_MAX) || defined(S_SPLINT_S)
230 typedef signed int int16_t;
231 #define INT16_C(v) ((int16_t)(v))
232 #ifndef PRINTF_INT16_MODIFIER
233 #define PRINTF_INT16_MODIFIER ""
234 #endif
235 #elif (SHRT_MAX == INT16_MAX)
236 typedef signed short int16_t;
237 #define INT16_C(v) ((int16_t)(v))
238 #ifndef PRINTF_INT16_MODIFIER
239 #define PRINTF_INT16_MODIFIER "h"
240 #endif
241 #else
242 #error "Platform not supported"
243 #endif
244 #endif
245 
246 #ifndef UINT32_MAX
247 #define UINT32_MAX (0xffffffffUL)
248 #endif
249 #ifndef uint32_t
250 #if (SIZE_MAX == UINT32_MAX) && !defined(S_SPLINT_S) && !defined(_lint)
251 typedef unsigned int uint32_t;
252 #ifndef PRINTF_INT32_MODIFIER
253 #define PRINTF_INT32_MODIFIER ""
254 #endif
255 #define UINT32_C(v) v##U
256 #elif (ULONG_MAX == UINT32_MAX) || defined(S_SPLINT_S)
257 typedef unsigned long uint32_t;
258 #define UINT32_C(v) v##UL
259 #ifndef PRINTF_INT32_MODIFIER
260 #define PRINTF_INT32_MODIFIER "l"
261 #endif
262 #elif (USHRT_MAX == UINT32_MAX)
263 typedef unsigned short uint32_t;
264 #define UINT32_C(v) ((unsigned short)(v))
265 #ifndef PRINTF_INT32_MODIFIER
266 #define PRINTF_INT32_MODIFIER ""
267 #endif
268 #else
269 #error "Platform not supported"
270 #endif
271 #endif
272 
273 #ifndef INT32_MAX
274 #define INT32_MAX (0x7fffffffL)
275 #endif
276 #ifndef INT32_MIN
277 #define INT32_MIN INT32_C(0x80000000)
278 #endif
279 #ifndef int32_t
280 #if (SIZE_MAX / 2 == INT32_MAX) && defined(__GNUC__) && (__GNUC__ > 3)
281 typedef signed int int32_t;
282 #define INT32_C(v) v
283 #ifndef PRINTF_INT32_MODIFIER
284 #define PRINTF_INT32_MODIFIER ""
285 #endif
286 #elif (LONG_MAX == INT32_MAX) || defined(S_SPLINT_S)
287 typedef signed long int32_t;
288 #define INT32_C(v) v##L
289 #ifndef PRINTF_INT32_MODIFIER
290 #define PRINTF_INT32_MODIFIER "l"
291 #endif
292 #elif (SIZE_MAX / 2 == INT32_MAX)
293 typedef signed int int32_t;
294 #define INT32_C(v) v
295 #ifndef PRINTF_INT32_MODIFIER
296 #define PRINTF_INT32_MODIFIER ""
297 #endif
298 #elif (SHRT_MAX == INT32_MAX)
299 typedef signed short int32_t;
300 #define INT32_C(v) ((short)(v))
301 #ifndef PRINTF_INT32_MODIFIER
302 #define PRINTF_INT32_MODIFIER ""
303 #endif
304 #else
305 #error "Platform not supported"
306 #endif
307 #endif
308 
309 /*
310  * The macro stdint_int64_defined is temporarily used to record
311  * whether or not 64 integer support is available. It must be
312  * defined for any 64 integer extensions for new platforms that are
313  * added.
314  */
315 
316 #undef stdint_int64_defined
317 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined(S_SPLINT_S)
318 #if (__STDC__ && __STDC_VERSION >= 199901L) || defined(S_SPLINT_S)
319 #define stdint_int64_defined
320 typedef long long int64_t;
321 typedef unsigned long long uint64_t;
322 #define UINT64_C(v) v##ULL
323 #define INT64_C(v) v##LL
324 #ifndef PRINTF_INT64_MODIFIER
325 #define PRINTF_INT64_MODIFIER "ll"
326 #endif
327 #endif
328 #endif
329 
330 #if !defined(stdint_int64_defined)
331 #if defined(__GNUC__) && __WORDSIZE == 64
332 #define stdint_int64_defined
333 __extension__ typedef long int64_t;
334 __extension__ typedef unsigned long uint64_t;
335 #define UINT64_C(v) v##UL
336 #define INT64_C(v) v##L
337 #ifndef PRINTF_INT64_MODIFIER
338 #define PRINTF_INT64_MODIFIER "l"
339 #endif
340 #elif defined(__GNUC__)
341 #define stdint_int64_defined
342 __extension__ typedef long long int64_t;
343 __extension__ typedef unsigned long long uint64_t;
344 #define UINT64_C(v) v##ULL
345 #define INT64_C(v) v##LL
346 #ifndef PRINTF_INT64_MODIFIER
347 #define PRINTF_INT64_MODIFIER "ll"
348 #endif
349 #elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || \
350  defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC) || \
351  defined(S_SPLINT_S)
352 #define stdint_int64_defined
353 typedef long long int64_t;
354 typedef unsigned long long uint64_t;
355 #define UINT64_C(v) v##ULL
356 #define INT64_C(v) v##LL
357 #ifndef PRINTF_INT64_MODIFIER
358 #define PRINTF_INT64_MODIFIER "ll"
359 #endif
360 #elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || \
361  (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || \
362  (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || \
363  defined(__DECC)
364 #define stdint_int64_defined
365 typedef __int64 int64_t;
366 typedef unsigned __int64 uint64_t;
367 #define UINT64_C(v) v##UI64
368 #define INT64_C(v) v##I64
369 #ifndef PRINTF_INT64_MODIFIER
370 #define PRINTF_INT64_MODIFIER "I64"
371 #endif
372 #endif
373 #endif
374 
375 #if !defined(LONG_LONG_MAX) && defined(INT64_C)
376 #define LONG_LONG_MAX INT64_C(9223372036854775807LL)
377 #endif
378 #ifndef ULONG_LONG_MAX
379 #define ULONG_LONG_MAX UINT64_C(18446744073709551615ULL)
380 #endif
381 
382 #if !defined(INT64_MAX) && defined(INT64_C)
383 #define INT64_MAX INT64_C(9223372036854775807LL)
384 #endif
385 #if !defined(INT64_MIN) && defined(INT64_C)
386 // lint -e(417)
387 #define INT64_MIN INT64_C(-9223372036854775808LL)
388 #endif
389 #if !defined(UINT64_MAX) && defined(INT64_C)
390 #define UINT64_MAX UINT64_C(18446744073709551615ULL)
391 #endif
392 
393 /*
394  * Width of hexadecimal for number field.
395  */
396 
397 #ifndef PRINTF_INT64_HEX_WIDTH
398 #define PRINTF_INT64_HEX_WIDTH "16"
399 #endif
400 #ifndef PRINTF_INT32_HEX_WIDTH
401 #define PRINTF_INT32_HEX_WIDTH "8"
402 #endif
403 #ifndef PRINTF_INT16_HEX_WIDTH
404 #define PRINTF_INT16_HEX_WIDTH "4"
405 #endif
406 #ifndef PRINTF_INT8_HEX_WIDTH
407 #define PRINTF_INT8_HEX_WIDTH "2"
408 #endif
409 
410 #ifndef PRINTF_INT64_DEC_WIDTH
411 #define PRINTF_INT64_DEC_WIDTH "20"
412 #endif
413 #ifndef PRINTF_INT32_DEC_WIDTH
414 #define PRINTF_INT32_DEC_WIDTH "10"
415 #endif
416 #ifndef PRINTF_INT16_DEC_WIDTH
417 #define PRINTF_INT16_DEC_WIDTH "5"
418 #endif
419 #ifndef PRINTF_INT8_DEC_WIDTH
420 #define PRINTF_INT8_DEC_WIDTH "3"
421 #endif
422 
423 /*
424  * Ok, lets not worry about 128 bit integers for now. Moore's law says
425  * we don't need to worry about that until about 2040 at which point
426  * we'll have bigger things to worry about.
427  */
428 
429 #ifdef stdint_int64_defined
430 typedef int64_t intmax_t;
431 typedef uint64_t uintmax_t;
432 #define INTMAX_MAX INT64_MAX
433 #define INTMAX_MIN INT64_MIN
434 #define UINTMAX_MAX UINT64_MAX
435 #define UINTMAX_C(v) UINT64_C(v)
436 #define INTMAX_C(v) INT64_C(v)
437 #ifndef PRINTF_INTMAX_MODIFIER
438 #define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
439 #endif
440 #ifndef PRINTF_INTMAX_HEX_WIDTH
441 #define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
442 #endif
443 #ifndef PRINTF_INTMAX_DEC_WIDTH
444 #define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
445 #endif
446 #else
449 #define INTMAX_MAX INT32_MAX
450 #define UINTMAX_MAX UINT32_MAX
451 #define UINTMAX_C(v) UINT32_C(v)
452 #define INTMAX_C(v) INT32_C(v)
453 #ifndef PRINTF_INTMAX_MODIFIER
454 #define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
455 #endif
456 #ifndef PRINTF_INTMAX_HEX_WIDTH
457 #define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
458 #endif
459 #ifndef PRINTF_INTMAX_DEC_WIDTH
460 #define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
461 #endif
462 #endif
463 
464 /*
465  * Because this file currently only supports platforms which have
466  * precise powers of 2 as bit sizes for the default integers, the
467  * least definitions are all trivial. Its possible that a future
468  * version of this file could have different definitions.
469  */
470 
471 #ifndef stdint_least_defined
478 #define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
479 #define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
480 #define UINT_LEAST8_MAX UINT8_MAX
481 #define INT_LEAST8_MAX INT8_MAX
482 #define UINT_LEAST16_MAX UINT16_MAX
483 #define INT_LEAST16_MAX INT16_MAX
484 #define UINT_LEAST32_MAX UINT32_MAX
485 #define INT_LEAST32_MAX INT32_MAX
486 #define INT_LEAST8_MIN INT8_MIN
487 #define INT_LEAST16_MIN INT16_MIN
488 #define INT_LEAST32_MIN INT32_MIN
489 #ifdef stdint_int64_defined
490 typedef int64_t int_least64_t;
491 typedef uint64_t uint_least64_t;
492 #define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
493 #define UINT_LEAST64_MAX UINT64_MAX
494 #define INT_LEAST64_MAX INT64_MAX
495 #define INT_LEAST64_MIN INT64_MIN
496 #endif
497 #endif
498 #undef stdint_least_defined
499 
500 /*
501  * The ANSI C committee pretending to know or specify anything about
502  * performance is the epitome of misguided arrogance. The mandate of
503  * this file is to *ONLY* ever support that absolute minimum
504  * definition of the fast integer types, for compatibility purposes.
505  * No extensions, and no attempt to suggest what may or may not be a
506  * faster integer type will ever be made in this file. Developers are
507  * warned to stay away from these types when using this or any other
508  * stdint.h.
509  */
510 
511 #ifndef int_fast8_t
513 #endif
514 #ifndef uint_fast8_t
516 #endif
517 #ifndef int_fast16_t
519 #endif
520 #ifndef uint_fast16_t
522 #endif
523 #ifndef int_fast32_t
525 #endif
526 #ifndef uint_fast32_t
528 #endif
529 #define UINT_FAST8_MAX UINT_LEAST8_MAX
530 #define INT_FAST8_MAX INT_LEAST8_MAX
531 #define UINT_FAST16_MAX UINT_LEAST16_MAX
532 #define INT_FAST16_MAX INT_LEAST16_MAX
533 #define UINT_FAST32_MAX UINT_LEAST32_MAX
534 #define INT_FAST32_MAX INT_LEAST32_MAX
535 #define INT_FAST8_MIN INT_LEAST8_MIN
536 #define INT_FAST16_MIN INT_LEAST16_MIN
537 #define INT_FAST32_MIN INT_LEAST32_MIN
538 #ifdef stdint_int64_defined
539 typedef int_least64_t int_fast64_t;
540 typedef uint_least64_t uint_fast64_t;
541 #define UINT_FAST64_MAX UINT_LEAST64_MAX
542 #define INT_FAST64_MAX INT_LEAST64_MAX
543 #define INT_FAST64_MIN INT_LEAST64_MIN
544 #endif
545 
546 /*
547  * Whatever piecemeal, per compiler thing we can do about the wchar_t
548  * type limits.
549  */
550 
551 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__GNUC__)
552 #include <wchar.h>
553 #ifndef WCHAR_MIN
554 #define WCHAR_MIN 0
555 #endif
556 #ifndef WCHAR_MAX
557 #define WCHAR_MAX ((wchar_t)-1)
558 #endif
559 #endif
560 
561 /*
562  * Whatever piecemeal, per compiler/platform thing we can do about the
563  * (u)intptr_t types and limits.
564  */
565 
566 #if defined(_MSC_VER) && defined(_UINTPTR_T_DEFINED)
567 #define STDINT_H_UINTPTR_T_DEFINED
568 #endif
569 
570 #ifndef STDINT_H_UINTPTR_T_DEFINED
571 #if defined(__alpha__) || defined(__ia64__) || defined(__x86_64__) || \
572  defined(_WIN64)
573 #define stdint_intptr_bits 64
574 #elif defined(__WATCOMC__) || defined(__TURBOC__)
575 #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
576 #define stdint_intptr_bits 16
577 #else
578 #define stdint_intptr_bits 32
579 #endif
580 #elif defined(__i386__) || defined(_WIN32) || defined(WIN32)
581 #define stdint_intptr_bits 32
582 #elif defined(__INTEL_COMPILER)
583 /* TODO -- what will Intel do about x86-64? */
584 #endif
585 
586 #ifdef stdint_intptr_bits
587 #define stdint_intptr_glue3_i(a, b, c) a##b##c
588 #define stdint_intptr_glue3(a, b, c) stdint_intptr_glue3_i(a, b, c)
589 #ifndef PRINTF_INTPTR_MODIFIER
590 #define PRINTF_INTPTR_MODIFIER \
591  stdint_intptr_glue3(PRINTF_INT, stdint_intptr_bits, _MODIFIER)
592 #endif
593 #ifndef PTRDIFF_MAX
594 #define PTRDIFF_MAX stdint_intptr_glue3(INT, stdint_intptr_bits, _MAX)
595 #endif
596 #ifndef PTRDIFF_MIN
597 #define PTRDIFF_MIN stdint_intptr_glue3(INT, stdint_intptr_bits, _MIN)
598 #endif
599 #ifndef UINTPTR_MAX
600 #define UINTPTR_MAX stdint_intptr_glue3(UINT, stdint_intptr_bits, _MAX)
601 #endif
602 #ifndef INTPTR_MAX
603 #define INTPTR_MAX stdint_intptr_glue3(INT, stdint_intptr_bits, _MAX)
604 #endif
605 #ifndef INTPTR_MIN
606 #define INTPTR_MIN stdint_intptr_glue3(INT, stdint_intptr_bits, _MIN)
607 #endif
608 #ifndef INTPTR_C
609 #define INTPTR_C(x) stdint_intptr_glue3(INT, stdint_intptr_bits, _C)(x)
610 #endif
611 #ifndef UINTPTR_C
612 #define UINTPTR_C(x) stdint_intptr_glue3(UINT, stdint_intptr_bits, _C)(x)
613 #endif
614 typedef stdint_intptr_glue3(uint, stdint_intptr_bits, _t) uintptr_t;
615 typedef stdint_intptr_glue3(int, stdint_intptr_bits, _t) intptr_t;
616 #else
617 /* TODO -- This following is likely wrong for some platforms, and does
618  nothing for the definition of uintptr_t. */
619 typedef ptrdiff_t intptr_t;
620 #endif
621 #define STDINT_H_UINTPTR_T_DEFINED
622 #endif
623 
624 /*
625  * Assumes sig_atomic_t is signed and we have a 2s complement machine.
626  */
627 
628 #ifndef SIG_ATOMIC_MAX
629 #define SIG_ATOMIC_MAX \
630  ((((sig_atomic_t)1) << (sizeof(sig_atomic_t) * CHAR_BIT - 1)) - 1)
631 #endif
632 
633 #endif
634 
635 #if defined(__TEST_PSTDINT_FOR_CORRECTNESS)
636 
637 /*
638  * Please compile with the maximum warning settings to make sure macros are not
639  * defined more than once.
640  */
641 
642 #include <stdlib.h>
643 #include <stdio.h>
644 #include <string.h>
645 
646 #define glue3_aux(x, y, z) x##y##z
647 #define glue3(x, y, z) glue3_aux(x, y, z)
648 
649 #define DECLU(bits) \
650  glue3(uint, bits, _t) glue3(u, bits, =) glue3(UINT, bits, _C)(0);
651 #define DECLI(bits) \
652  glue3(int, bits, _t) glue3(i, bits, =) glue3(INT, bits, _C)(0);
653 
654 #define DECL(us, bits) glue3(DECL, us, )(bits)
655 
656 #define TESTUMAX(bits) \
657  glue3(u, bits, =) glue3(~, u, bits); \
658  if (glue3(UINT, bits, _MAX) glue3(!=, u, bits)) \
659  printf("Something wrong with UINT%d_MAX\n", bits)
660 
661 int main()
662 {
663  DECL(I, 8)
664  DECL(U, 8)
665  DECL(I, 16)
666  DECL(U, 16)
667  DECL(I, 32)
668  DECL(U, 32)
669 #ifdef INT64_MAX
670  DECL(I, 64)
671  DECL(U, 64)
672 #endif
673  intmax_t imax = INTMAX_C(0);
674  uintmax_t umax = UINTMAX_C(0);
675  char str0[256], str1[256];
676 
677  sprintf(str0, "%d %x\n", 0, ~0);
678 
679  sprintf(str1, "%d %x\n", i8, ~0);
680  if (0 != strcmp(str0, str1)) printf("Something wrong with i8 : %s\n", str1);
681  sprintf(str1, "%u %x\n", u8, ~0);
682  if (0 != strcmp(str0, str1)) printf("Something wrong with u8 : %s\n", str1);
683  sprintf(str1, "%d %x\n", i16, ~0);
684  if (0 != strcmp(str0, str1))
685  printf("Something wrong with i16 : %s\n", str1);
686  sprintf(str1, "%u %x\n", u16, ~0);
687  if (0 != strcmp(str0, str1))
688  printf("Something wrong with u16 : %s\n", str1);
689  sprintf(str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
690  if (0 != strcmp(str0, str1))
691  printf("Something wrong with i32 : %s\n", str1);
692  sprintf(str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
693  if (0 != strcmp(str0, str1))
694  printf("Something wrong with u32 : %s\n", str1);
695 #ifdef INT64_MAX
696  sprintf(str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
697  if (0 != strcmp(str0, str1))
698  printf("Something wrong with i64 : %s\n", str1);
699 #endif
700  sprintf(str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
701  if (0 != strcmp(str0, str1))
702  printf("Something wrong with imax : %s\n", str1);
703  sprintf(str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
704  if (0 != strcmp(str0, str1))
705  printf("Something wrong with umax : %s\n", str1);
706 
707  TESTUMAX(8);
708  TESTUMAX(16);
709  TESTUMAX(32);
710 #ifdef INT64_MAX
711  TESTUMAX(64);
712 #endif
713 
714  return EXIT_SUCCESS;
715 }
716 
717 #endif
718 
719 #if defined(_STDINT) && defined(_MSC_VER)
720 #define stdint_int64_defined
721 #endif
722 
723 #endif // file guard
unsigned __int16 uint16_t
Definition: rptypes.h:44
uint16_t uint_least16_t
signed char int8_t
Definition: rptypes.h:40
unsigned char uint8_t
Definition: rptypes.h:41
__int16 int16_t
Definition: rptypes.h:43
__int64 int64_t
Definition: rptypes.h:49
int32_t intmax_t
int_least16_t int_fast16_t
uint32_t uint_least32_t
uint8_t uint_least8_t
_W64 int ptrdiff_t
Definition: glew.h:137
__int32 int32_t
Definition: rptypes.h:46
unsigned __int64 uint64_t
Definition: rptypes.h:50
uint32_t uintmax_t
int32_t int_least32_t
int8_t int_least8_t
#define stdint_intptr_glue3(a, b, c)
int16_t int_least16_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
uint_least8_t uint_fast8_t
int_least32_t int_fast32_t
uint_least16_t uint_fast16_t
uint_least32_t uint_fast32_t
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:189



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020