Main MRPT website > C++ reference for MRPT 1.5.6
hwdrivers/src/xSens_MT4/xstypes/include/xsens/pstdint.h
Go to the documentation of this file.
1 /* A portable stdint.h
2  ****************************************************************************
3  * BSD License:
4  ****************************************************************************
5  *
6  * Copyright (c) 2005-2007 Paul Hsieh
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************
33  *
34  * Version 0.1.11
35  *
36  * The ANSI C standard committee, for the C99 standard, specified the
37  * inclusion of a new standard include file called stdint.h. This is
38  * a very useful and long desired include file which contains several
39  * very precise definitions for integer scalar types that is
40  * critically important for making portable several classes of
41  * applications including cryptography, hashing, variable length
42  * integer libraries and so on. But for most developers its likely
43  * useful just for programming sanity.
44  *
45  * The problem is that most compiler vendors have decided not to
46  * implement the C99 standard, and the next C++ language standard
47  * (which has a lot more mindshare these days) will be a long time in
48  * coming and its unknown whether or not it will include stdint.h or
49  * how much adoption it will have. Either way, it will be a long time
50  * before all compilers come with a stdint.h and it also does nothing
51  * for the extremely large number of compilers available today which
52  * do not include this file, or anything comparable to it.
53  *
54  * So that's what this file is all about. Its an attempt to build a
55  * single universal include file that works on as many platforms as
56  * possible to deliver what stdint.h is supposed to. A few things
57  * that should be noted about this file:
58  *
59  * 1) It is not guaranteed to be portable and/or present an identical
60  * interface on all platforms. The extreme variability of the
61  * ANSI C standard makes this an impossibility right from the
62  * very get go. Its really only meant to be useful for the vast
63  * majority of platforms that possess the capability of
64  * implementing usefully and precisely defined, standard sized
65  * integer scalars. Systems which are not intrinsically 2s
66  * complement may produce invalid constants.
67  *
68  * 2) There is an unavoidable use of non-reserved symbols.
69  *
70  * 3) Other standard include files are invoked.
71  *
72  * 4) This file may come in conflict with future platforms that do
73  * include stdint.h. The hope is that one or the other can be
74  * used with no real difference.
75  *
76  * 5) In the current verison, if your platform can't represent
77  * int32_t, int16_t and int8_t, it just dumps out with a compiler
78  * error.
79  *
80  * 6) 64 bit integers may or may not be defined. Test for their
81  * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
82  * Note that this is different from the C99 specification which
83  * requires the existence of 64 bit support in the compiler. If
84  * this is not defined for your platform, yet it is capable of
85  * dealing with 64 bits then it is because this file has not yet
86  * been extended to cover all of your system's capabilities.
87  *
88  * 7) (u)intptr_t may or may not be defined. Test for its presence
89  * with the test: #ifdef PTRDIFF_MAX. If this is not defined
90  * for your platform, then it is because this file has not yet
91  * been extended to cover all of your system's capabilities, not
92  * because its optional.
93  *
94  * 8) The following might not been defined even if your platform is
95  * capable of defining it:
96  *
97  * WCHAR_MIN
98  * WCHAR_MAX
99  * (u)int64_t
100  * PTRDIFF_MIN
101  * PTRDIFF_MAX
102  * (u)intptr_t
103  *
104  * 9) The following have not been defined:
105  *
106  * WINT_MIN
107  * WINT_MAX
108  *
109  * 10) The criteria for defining (u)int_least(*)_t isn't clear,
110  * except for systems which don't have a type that precisely
111  * defined 8, 16, or 32 bit types (which this include file does
112  * not support anyways). Default definitions have been given.
113  *
114  * 11) The criteria for defining (u)int_fast(*)_t isn't something I
115  * would trust to any particular compiler vendor or the ANSI C
116  * committee. It is well known that "compatible systems" are
117  * commonly created that have very different performance
118  * characteristics from the systems they are compatible with,
119  * especially those whose vendors make both the compiler and the
120  * system. Default definitions have been given, but its strongly
121  * recommended that users never use these definitions for any
122  * reason (they do *NOT* deliver any serious guarantee of
123  * improved performance -- not in this file, nor any vendor's
124  * stdint.h).
125  *
126  * 12) The following macros:
127  *
128  * PRINTF_INTMAX_MODIFIER
129  * PRINTF_INT64_MODIFIER
130  * PRINTF_INT32_MODIFIER
131  * PRINTF_INT16_MODIFIER
132  * PRINTF_LEAST64_MODIFIER
133  * PRINTF_LEAST32_MODIFIER
134  * PRINTF_LEAST16_MODIFIER
135  * PRINTF_INTPTR_MODIFIER
136  *
137  * are strings which have been defined as the modifiers required
138  * for the "d", "u" and "x" printf formats to correctly output
139  * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
140  * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
141  * PRINTF_INTPTR_MODIFIER is not defined for some systems which
142  * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
143  * defined if INT64_MAX is not defined. These are an extension
144  * beyond what C99 specifies must be in stdint.h.
145  *
146  * In addition, the following macros are defined:
147  *
148  * PRINTF_INTMAX_HEX_WIDTH
149  * PRINTF_INT64_HEX_WIDTH
150  * PRINTF_INT32_HEX_WIDTH
151  * PRINTF_INT16_HEX_WIDTH
152  * PRINTF_INT8_HEX_WIDTH
153  * PRINTF_INTMAX_DEC_WIDTH
154  * PRINTF_INT64_DEC_WIDTH
155  * PRINTF_INT32_DEC_WIDTH
156  * PRINTF_INT16_DEC_WIDTH
157  * PRINTF_INT8_DEC_WIDTH
158  *
159  * Which specifies the maximum number of characters required to
160  * print the number of that type in either hexadecimal or decimal.
161  * These are an extension beyond what C99 specifies must be in
162  * stdint.h.
163  *
164  * Compilers tested (all with 0 warnings at their highest respective
165  * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
166  * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
167  * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
168  *
169  * This file should be considered a work in progress. Suggestions for
170  * improvements, especially those which increase coverage are strongly
171  * encouraged.
172  *
173  * Acknowledgements
174  *
175  * The following people have made significant contributions to the
176  * development and testing of this file:
177  *
178  * Chris Howie
179  * John Steele Scott
180  * Dave Thorup
181  *
182  */
183 
184 #ifndef _PSTDINT_H_INCLUDED
185 #include <stddef.h>
186 #include <limits.h>
187 
188 /*
189  * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
190  * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
191  */
192 
193 #if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && __WATCOMC__ >= 1250) || (defined(__GNUC__) && __GNUC__ > 2) || (defined(_MSC_VER) && _MSC_VER >= 1600) || defined(IAR_ARM_CM3) || (defined(__ICCARM__) && __ICCARM__) || (defined(_ADI_COMPILER) && _ADI_COMPILER) || (defined(__ICC8051__) && __ICC8051__)
194 #include <stdint.h>
195 #endif
196 
197 #if (defined (_STDINT_H_INCLUDED) || defined (_STDINT) || defined (_STDINT_H) || defined (_STDINT_H_) || defined (BOOST_CSTDINT_HPP)) && !defined (_PSTDINT_H_INCLUDED)
198 #define _PSTDINT_H_INCLUDED
199 # ifndef PRINTF_INT64_MODIFIER
200 # if (__WORDSIZE == 64) && !defined(__APPLE__) //lint !e553 __WORDSIZE should always be defined at this point
201 # define PRINTF_INT64_MODIFIER "l"
202 # else
203 # define PRINTF_INT64_MODIFIER "ll"
204 # endif
205 # endif
206 # ifndef PRINTF_INT32_MODIFIER
207 /* There might be cases where this needs to be "l". */
208 # define PRINTF_INT32_MODIFIER ""
209 # endif
210 # ifndef PRINTF_INT16_MODIFIER
211 # define PRINTF_INT16_MODIFIER "h"
212 # endif
213 # ifndef PRINTF_INTMAX_MODIFIER
214 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
215 # endif
216 # ifndef PRINTF_INT64_HEX_WIDTH
217 # define PRINTF_INT64_HEX_WIDTH "16"
218 # endif
219 # ifndef PRINTF_INT32_HEX_WIDTH
220 # define PRINTF_INT32_HEX_WIDTH "8"
221 # endif
222 # ifndef PRINTF_INT16_HEX_WIDTH
223 # define PRINTF_INT16_HEX_WIDTH "4"
224 # endif
225 # ifndef PRINTF_INT8_HEX_WIDTH
226 # define PRINTF_INT8_HEX_WIDTH "2"
227 # endif
228 # ifndef PRINTF_INT64_DEC_WIDTH
229 # define PRINTF_INT64_DEC_WIDTH "20"
230 # endif
231 # ifndef PRINTF_INT32_DEC_WIDTH
232 # define PRINTF_INT32_DEC_WIDTH "10"
233 # endif
234 # ifndef PRINTF_INT16_DEC_WIDTH
235 # define PRINTF_INT16_DEC_WIDTH "5"
236 # endif
237 # ifndef PRINTF_INT8_DEC_WIDTH
238 # define PRINTF_INT8_DEC_WIDTH "3"
239 # endif
240 # ifndef PRINTF_INTMAX_HEX_WIDTH
241 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
242 # endif
243 # ifndef PRINTF_INTMAX_DEC_WIDTH
244 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
245 # endif
246 
247 /*
248  * Something really weird is going on with Open Watcom. Just pull some of
249  * these duplicated definitions from Open Watcom's stdint.h file for now.
250  */
251 
252 # if defined (__WATCOMC__) && __WATCOMC__ >= 1250
253 # if !defined (INT64_C)
254 # define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
255 # endif
256 # if !defined (UINT64_C)
257 # define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
258 # endif
259 # if !defined (INT32_C)
260 # define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
261 # endif
262 # if !defined (UINT32_C)
263 # define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
264 # endif
265 # if !defined (INT16_C)
266 # define INT16_C(x) (x)
267 # endif
268 # if !defined (UINT16_C)
269 # define UINT16_C(x) (x)
270 # endif
271 # if !defined (INT8_C)
272 # define INT8_C(x) (x)
273 # endif
274 # if !defined (UINT8_C)
275 # define UINT8_C(x) (x)
276 # endif
277 # if !defined (UINT64_MAX)
278 # define UINT64_MAX 18446744073709551615ULL
279 # endif
280 # if !defined (INT64_MAX)
281 # define INT64_MAX 9223372036854775807LL
282 # endif
283 # if !defined (UINT32_MAX)
284 # define UINT32_MAX 4294967295UL
285 # endif
286 # if !defined (INT32_MAX)
287 # define INT32_MAX 2147483647L
288 # endif
289 # if !defined (INTMAX_MAX)
290 # define INTMAX_MAX INT64_MAX
291 # endif
292 # if !defined (INTMAX_MIN)
293 # define INTMAX_MIN INT64_MIN
294 # endif
295 # endif
296 
297 /* Some of the targets compiled by Visual Dsp++ (like the Sharc) do not have a notion of 8bit of 16bit value
298  We define these here although the actual storage size is 32 bits
299 */
300 #if (defined(_ADI_COMPILER) && _ADI_COMPILER)
301 # ifndef int8_t
302  typedef signed char int8_t;
303 # endif
304 # ifndef uint8_t
305  typedef unsigned char uint8_t;
306 # endif
307 # ifndef int16_t
308  typedef signed short int16_t;
309 # endif
310 # ifndef uint16_t
311  typedef unsigned short uint16_t;
312 # endif
313 #endif //(defined(_ADI_COMPILER) && _ADI_COMPILER)
314 
315 #endif
316 
317 #ifndef _PSTDINT_H_INCLUDED
318 #define _PSTDINT_H_INCLUDED
319 
320 #ifndef SIZE_MAX
321 #ifdef DOXYGEN
322 # define SIZE_MAX (~0)
323 #else
324 # define SIZE_MAX (~(size_t)0)
325 #endif
326 #endif
327 
328 /*
329  * Deduce the type assignments from limits.h under the assumption that
330  * integer sizes in bits are powers of 2, and follow the ANSI
331  * definitions.
332  */
333 
334 #ifndef UINT8_MAX
335 # define UINT8_MAX 0xff
336 #endif
337 #ifndef uint8_t
338 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
339  typedef unsigned char uint8_t;
340 # define UINT8_C(v) ((uint8_t) v)
341 # else
342 # error "Platform not supported"
343 # endif
344 #endif
345 
346 #ifndef INT8_MAX
347 # define INT8_MAX 0x7f
348 #endif
349 #ifndef INT8_MIN
350 # define INT8_MIN INT8_C(0x80)
351 #endif
352 #ifndef int8_t
353 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
354  typedef signed char int8_t;
355 # define INT8_C(v) ((int8_t) v)
356 # else
357 # error "Platform not supported"
358 # endif
359 #endif
360 
361 #ifndef UINT16_MAX
362 # define UINT16_MAX 0xffff
363 #endif
364 #ifndef uint16_t
365 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
366  typedef unsigned int uint16_t;
367 # ifndef PRINTF_INT16_MODIFIER
368 # define PRINTF_INT16_MODIFIER ""
369 # endif
370 # define UINT16_C(v) ((uint16_t) (v))
371 #elif (USHRT_MAX == UINT16_MAX)
372  typedef unsigned short uint16_t;
373 # define UINT16_C(v) ((uint16_t) (v))
374 # ifndef PRINTF_INT16_MODIFIER
375 # define PRINTF_INT16_MODIFIER "h"
376 # endif
377 #else
378 #error "Platform not supported"
379 #endif
380 #endif
381 
382 #ifndef INT16_MAX
383 # define INT16_MAX 0x7fff
384 #endif
385 #ifndef INT16_MIN
386 # define INT16_MIN INT16_C(0x8000)
387 #endif
388 #ifndef int16_t
389 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
390  typedef signed int int16_t;
391 # define INT16_C(v) ((int16_t) (v))
392 # ifndef PRINTF_INT16_MODIFIER
393 # define PRINTF_INT16_MODIFIER ""
394 # endif
395 #elif (SHRT_MAX == INT16_MAX)
396  typedef signed short int16_t;
397 # define INT16_C(v) ((int16_t) (v))
398 # ifndef PRINTF_INT16_MODIFIER
399 # define PRINTF_INT16_MODIFIER "h"
400 # endif
401 #else
402 #error "Platform not supported"
403 #endif
404 #endif
405 
406 #ifndef UINT32_MAX
407 # define UINT32_MAX (0xffffffffUL)
408 #endif
409 #ifndef uint32_t
410 #if (SIZE_MAX == UINT32_MAX) && !defined (S_SPLINT_S) && !defined(_lint)
411 typedef unsigned int uint32_t;
412 # ifndef PRINTF_INT32_MODIFIER
413 # define PRINTF_INT32_MODIFIER ""
414 # endif
415 # define UINT32_C(v) v ## U
416 #elif (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
417  typedef unsigned long uint32_t;
418 # define UINT32_C(v) v ## UL
419 # ifndef PRINTF_INT32_MODIFIER
420 # define PRINTF_INT32_MODIFIER "l"
421 # endif
422 #elif (USHRT_MAX == UINT32_MAX)
423  typedef unsigned short uint32_t;
424 # define UINT32_C(v) ((unsigned short) (v))
425 # ifndef PRINTF_INT32_MODIFIER
426 # define PRINTF_INT32_MODIFIER ""
427 # endif
428 #else
429 #error "Platform not supported"
430 #endif
431 #endif
432 
433 #ifndef INT32_MAX
434 # define INT32_MAX (0x7fffffffL)
435 #endif
436 #ifndef INT32_MIN
437 # define INT32_MIN INT32_C(0x80000000)
438 #endif
439 #ifndef int32_t
440 #if (SIZE_MAX/2 == INT32_MAX) && defined (__GNUC__) && (__GNUC__ > 3)
441  typedef signed int int32_t;
442 # define INT32_C(v) v
443 # ifndef PRINTF_INT32_MODIFIER
444 # define PRINTF_INT32_MODIFIER ""
445 # endif
446 #elif (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
447  typedef signed long int32_t;
448 # define INT32_C(v) v ## L
449 # ifndef PRINTF_INT32_MODIFIER
450 # define PRINTF_INT32_MODIFIER "l"
451 # endif
452 #elif (SIZE_MAX/2 == INT32_MAX)
453  typedef signed int int32_t;
454 # define INT32_C(v) v
455 # ifndef PRINTF_INT32_MODIFIER
456 # define PRINTF_INT32_MODIFIER ""
457 # endif
458 #elif (SHRT_MAX == INT32_MAX)
459  typedef signed short int32_t;
460 # define INT32_C(v) ((short) (v))
461 # ifndef PRINTF_INT32_MODIFIER
462 # define PRINTF_INT32_MODIFIER ""
463 # endif
464 #else
465 #error "Platform not supported"
466 #endif
467 #endif
468 
469 /*
470  * The macro stdint_int64_defined is temporarily used to record
471  * whether or not 64 integer support is available. It must be
472  * defined for any 64 integer extensions for new platforms that are
473  * added.
474  */
475 
476 #undef stdint_int64_defined
477 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
478 # if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
479 # define stdint_int64_defined
480  typedef long long int64_t;
481  typedef unsigned long long uint64_t;
482 # define UINT64_C(v) v ## ULL
483 # define INT64_C(v) v ## LL
484 # ifndef PRINTF_INT64_MODIFIER
485 # define PRINTF_INT64_MODIFIER "ll"
486 # endif
487 # endif
488 #endif
489 
490 #if !defined (stdint_int64_defined)
491 # if defined(__GNUC__) && __WORDSIZE == 64
492 # define stdint_int64_defined
493  __extension__ typedef long int64_t;
494  __extension__ typedef unsigned long uint64_t;
495 # define UINT64_C(v) v ## UL
496 # define INT64_C(v) v ## L
497 # ifndef PRINTF_INT64_MODIFIER
498 # define PRINTF_INT64_MODIFIER "l"
499 # endif
500 #elif defined(__GNUC__)
501 # define stdint_int64_defined
502  __extension__ typedef long long int64_t;
503  __extension__ typedef unsigned long long uint64_t;
504 # define UINT64_C(v) v ## ULL
505 # define INT64_C(v) v ## LL
506 # ifndef PRINTF_INT64_MODIFIER
507 # define PRINTF_INT64_MODIFIER "ll"
508 # endif
509 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
510 # define stdint_int64_defined
511  typedef long long int64_t;
512  typedef unsigned long long uint64_t;
513 # define UINT64_C(v) v ## ULL
514 # define INT64_C(v) v ## LL
515 # ifndef PRINTF_INT64_MODIFIER
516 # define PRINTF_INT64_MODIFIER "ll"
517 # endif
518 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
519 # define stdint_int64_defined
520  typedef __int64 int64_t;
521  typedef unsigned __int64 uint64_t;
522 # define UINT64_C(v) v ## UI64
523 # define INT64_C(v) v ## I64
524 # ifndef PRINTF_INT64_MODIFIER
525 # define PRINTF_INT64_MODIFIER "I64"
526 # endif
527 # endif
528 #endif
529 
530 #if !defined (LONG_LONG_MAX) && defined (INT64_C)
531 # define LONG_LONG_MAX INT64_C (9223372036854775807LL)
532 #endif
533 #ifndef ULONG_LONG_MAX
534 # define ULONG_LONG_MAX UINT64_C (18446744073709551615ULL)
535 #endif
536 
537 #if !defined (INT64_MAX) && defined (INT64_C)
538 # define INT64_MAX INT64_C (9223372036854775807LL)
539 #endif
540 #if !defined (INT64_MIN) && defined (INT64_C)
541 //lint -e(417)
542 # define INT64_MIN INT64_C (-9223372036854775808LL)
543 #endif
544 #if !defined (UINT64_MAX) && defined (INT64_C)
545 # define UINT64_MAX UINT64_C (18446744073709551615ULL)
546 #endif
547 
548 /*
549  * Width of hexadecimal for number field.
550  */
551 
552 #ifndef PRINTF_INT64_HEX_WIDTH
553 # define PRINTF_INT64_HEX_WIDTH "16"
554 #endif
555 #ifndef PRINTF_INT32_HEX_WIDTH
556 # define PRINTF_INT32_HEX_WIDTH "8"
557 #endif
558 #ifndef PRINTF_INT16_HEX_WIDTH
559 # define PRINTF_INT16_HEX_WIDTH "4"
560 #endif
561 #ifndef PRINTF_INT8_HEX_WIDTH
562 # define PRINTF_INT8_HEX_WIDTH "2"
563 #endif
564 
565 #ifndef PRINTF_INT64_DEC_WIDTH
566 # define PRINTF_INT64_DEC_WIDTH "20"
567 #endif
568 #ifndef PRINTF_INT32_DEC_WIDTH
569 # define PRINTF_INT32_DEC_WIDTH "10"
570 #endif
571 #ifndef PRINTF_INT16_DEC_WIDTH
572 # define PRINTF_INT16_DEC_WIDTH "5"
573 #endif
574 #ifndef PRINTF_INT8_DEC_WIDTH
575 # define PRINTF_INT8_DEC_WIDTH "3"
576 #endif
577 
578 /*
579  * Ok, lets not worry about 128 bit integers for now. Moore's law says
580  * we don't need to worry about that until about 2040 at which point
581  * we'll have bigger things to worry about.
582  */
583 
584 #ifdef stdint_int64_defined
585  typedef int64_t intmax_t;
586  typedef uint64_t uintmax_t;
587 # define INTMAX_MAX INT64_MAX
588 # define INTMAX_MIN INT64_MIN
589 # define UINTMAX_MAX UINT64_MAX
590 # define UINTMAX_C(v) UINT64_C(v)
591 # define INTMAX_C(v) INT64_C(v)
592 # ifndef PRINTF_INTMAX_MODIFIER
593 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
594 # endif
595 # ifndef PRINTF_INTMAX_HEX_WIDTH
596 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
597 # endif
598 # ifndef PRINTF_INTMAX_DEC_WIDTH
599 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
600 # endif
601 #else
602  typedef int32_t intmax_t;
604 # define INTMAX_MAX INT32_MAX
605 # define UINTMAX_MAX UINT32_MAX
606 # define UINTMAX_C(v) UINT32_C(v)
607 # define INTMAX_C(v) INT32_C(v)
608 # ifndef PRINTF_INTMAX_MODIFIER
609 # define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
610 # endif
611 # ifndef PRINTF_INTMAX_HEX_WIDTH
612 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
613 # endif
614 # ifndef PRINTF_INTMAX_DEC_WIDTH
615 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
616 # endif
617 #endif
618 
619 /*
620  * Because this file currently only supports platforms which have
621  * precise powers of 2 as bit sizes for the default integers, the
622  * least definitions are all trivial. Its possible that a future
623  * version of this file could have different definitions.
624  */
625 
626 #ifndef stdint_least_defined
633 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
634 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
635 # define UINT_LEAST8_MAX UINT8_MAX
636 # define INT_LEAST8_MAX INT8_MAX
637 # define UINT_LEAST16_MAX UINT16_MAX
638 # define INT_LEAST16_MAX INT16_MAX
639 # define UINT_LEAST32_MAX UINT32_MAX
640 # define INT_LEAST32_MAX INT32_MAX
641 # define INT_LEAST8_MIN INT8_MIN
642 # define INT_LEAST16_MIN INT16_MIN
643 # define INT_LEAST32_MIN INT32_MIN
644 # ifdef stdint_int64_defined
645  typedef int64_t int_least64_t;
646  typedef uint64_t uint_least64_t;
647 # define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
648 # define UINT_LEAST64_MAX UINT64_MAX
649 # define INT_LEAST64_MAX INT64_MAX
650 # define INT_LEAST64_MIN INT64_MIN
651 # endif
652 #endif
653 #undef stdint_least_defined
654 
655 /*
656  * The ANSI C committee pretending to know or specify anything about
657  * performance is the epitome of misguided arrogance. The mandate of
658  * this file is to *ONLY* ever support that absolute minimum
659  * definition of the fast integer types, for compatibility purposes.
660  * No extensions, and no attempt to suggest what may or may not be a
661  * faster integer type will ever be made in this file. Developers are
662  * warned to stay away from these types when using this or any other
663  * stdint.h.
664  */
665 
666 #ifndef int_fast8_t
668 #endif
669 #ifndef uint_fast8_t
671 #endif
672 #ifndef int_fast16_t
674 #endif
675 #ifndef uint_fast16_t
677 #endif
678 #ifndef int_fast32_t
680 #endif
681 #ifndef uint_fast32_t
683 #endif
684 #define UINT_FAST8_MAX UINT_LEAST8_MAX
685 #define INT_FAST8_MAX INT_LEAST8_MAX
686 #define UINT_FAST16_MAX UINT_LEAST16_MAX
687 #define INT_FAST16_MAX INT_LEAST16_MAX
688 #define UINT_FAST32_MAX UINT_LEAST32_MAX
689 #define INT_FAST32_MAX INT_LEAST32_MAX
690 #define INT_FAST8_MIN INT_LEAST8_MIN
691 #define INT_FAST16_MIN INT_LEAST16_MIN
692 #define INT_FAST32_MIN INT_LEAST32_MIN
693 #ifdef stdint_int64_defined
694  typedef int_least64_t int_fast64_t;
695  typedef uint_least64_t uint_fast64_t;
696 # define UINT_FAST64_MAX UINT_LEAST64_MAX
697 # define INT_FAST64_MAX INT_LEAST64_MAX
698 # define INT_FAST64_MIN INT_LEAST64_MIN
699 #endif
700 
701 /*
702  * Whatever piecemeal, per compiler thing we can do about the wchar_t
703  * type limits.
704  */
705 
706 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
707 # include <wchar.h>
708 # ifndef WCHAR_MIN
709 # define WCHAR_MIN 0
710 # endif
711 # ifndef WCHAR_MAX
712 # define WCHAR_MAX ((wchar_t)-1)
713 # endif
714 #endif
715 
716 /*
717  * Whatever piecemeal, per compiler/platform thing we can do about the
718  * (u)intptr_t types and limits.
719  */
720 
721 #if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
722 # define STDINT_H_UINTPTR_T_DEFINED
723 #endif
724 
725 #ifndef STDINT_H_UINTPTR_T_DEFINED
726 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
727 # define stdint_intptr_bits 64
728 # elif defined (__WATCOMC__) || defined (__TURBOC__)
729 # if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
730 # define stdint_intptr_bits 16
731 # else
732 # define stdint_intptr_bits 32
733 # endif
734 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
735 # define stdint_intptr_bits 32
736 # elif defined (__INTEL_COMPILER)
737 /* TODO -- what will Intel do about x86-64? */
738 # endif
739 
740 # ifdef stdint_intptr_bits
741 # define stdint_intptr_glue3_i(a,b,c) a##b##c
742 # define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
743 # ifndef PRINTF_INTPTR_MODIFIER
744 # define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
745 # endif
746 # ifndef PTRDIFF_MAX
747 # define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
748 # endif
749 # ifndef PTRDIFF_MIN
750 # define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
751 # endif
752 # ifndef UINTPTR_MAX
753 # define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
754 # endif
755 # ifndef INTPTR_MAX
756 # define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
757 # endif
758 # ifndef INTPTR_MIN
759 # define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
760 # endif
761 # ifndef INTPTR_C
762 # define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
763 # endif
764 # ifndef UINTPTR_C
765 # define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
766 # endif
767  typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
768  typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
769 # else
770 /* TODO -- This following is likely wrong for some platforms, and does
771  nothing for the definition of uintptr_t. */
772  typedef ptrdiff_t intptr_t;
773 # endif
774 # define STDINT_H_UINTPTR_T_DEFINED
775 #endif
776 
777 /*
778  * Assumes sig_atomic_t is signed and we have a 2s complement machine.
779  */
780 
781 #ifndef SIG_ATOMIC_MAX
782 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
783 #endif
784 
785 #endif
786 
787 #if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
788 
789 /*
790  * Please compile with the maximum warning settings to make sure macros are not
791  * defined more than once.
792  */
793 
794 #include <stdlib.h>
795 #include <stdio.h>
796 #include <string.h>
797 
798 #define glue3_aux(x,y,z) x ## y ## z
799 #define glue3(x,y,z) glue3_aux(x,y,z)
800 
801 #define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
802 #define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
803 
804 #define DECL(us,bits) glue3(DECL,us,) (bits)
805 
806 #define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
807 
808 int main () {
809  DECL(I,8)
810  DECL(U,8)
811  DECL(I,16)
812  DECL(U,16)
813  DECL(I,32)
814  DECL(U,32)
815 #ifdef INT64_MAX
816  DECL(I,64)
817  DECL(U,64)
818 #endif
819  intmax_t imax = INTMAX_C(0);
820  uintmax_t umax = UINTMAX_C(0);
821  char str0[256], str1[256];
822 
823  sprintf (str0, "%d %x\n", 0, ~0);
824 
825  sprintf (str1, "%d %x\n", i8, ~0);
826  if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
827  sprintf (str1, "%u %x\n", u8, ~0);
828  if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
829  sprintf (str1, "%d %x\n", i16, ~0);
830  if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
831  sprintf (str1, "%u %x\n", u16, ~0);
832  if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
833  sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
834  if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
835  sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
836  if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
837 #ifdef INT64_MAX
838  sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
839  if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
840 #endif
841  sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
842  if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
843  sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
844  if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
845 
846  TESTUMAX(8);
847  TESTUMAX(16);
848  TESTUMAX(32);
849 #ifdef INT64_MAX
850  TESTUMAX(64);
851 #endif
852 
853  return EXIT_SUCCESS;
854 }
855 
856 #endif
857 
858 #if defined(_STDINT) && defined(_MSC_VER)
859 #define stdint_int64_defined
860 #endif
861 
862 
863 #endif // file guard
uint16_t uint_least16_t
unsigned __int16 uint16_t
Definition: rptypes.h:46
uint32_t uint_least32_t
signed char int8_t
Definition: rptypes.h:42
unsigned char uint8_t
Definition: rptypes.h:43
__int16 int16_t
Definition: rptypes.h:45
__int64 int64_t
Definition: rptypes.h:51
_W64 int ptrdiff_t
Definition: glew.h:133
__int32 int32_t
Definition: rptypes.h:48
unsigned __int64 uint64_t
Definition: rptypes.h:52
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS 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:191
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019