AVR Libc Home Page AVRs AVR Libc Development Pages
Main Page User Manual Library Reference FAQ Alphabetical Index Example Projects

stdint.h
Go to the documentation of this file.
1 /* Copyright (c) 2002,2004,2005 Marek Michalkiewicz
2  Copyright (c) 2005, Carlos Lamas
3  Copyright (c) 2005,2007 Joerg Wunsch
4  Copyright (c) 2013 Embecosm
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 
13  * Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in
15  the documentation and/or other materials provided with the
16  distribution.
17 
18  * Neither the name of the copyright holders nor the names of
19  contributors may be used to endorse or promote products derived
20  from this software without specific prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  POSSIBILITY OF SUCH DAMAGE. */
33 
34 /* $Id: stdint.h 2426 2014-05-01 12:49:30Z amylaar $ */
35 
36 /*
37  * ISO/IEC 9899:1999 7.18 Integer types <stdint.h>
38  */
39 
40 #ifndef __STDINT_H_
41 #define __STDINT_H_
42 
43 /** \file */
44 /** \defgroup avr_stdint <stdint.h>: Standard Integer Types
45  \code #include <stdint.h> \endcode
46 
47  Use [u]intN_t if you need exactly N bits.
48 
49  Since these typedefs are mandated by the C99 standard, they are preferred
50  over rolling your own typedefs. */
51 
52 /*
53  * __USING_MINT8 is defined to 1 if the -mint8 option is in effect.
54  */
55 #if __INT_MAX__ == 127
56 # define __USING_MINT8 1
57 #else
58 # define __USING_MINT8 0
59 #endif
60 
61 /* Integer types */
62 
63 #if defined(__DOXYGEN__)
64 
65 /* doxygen gets confused by the __attribute__ stuff */
66 
67 /** \name Exact-width integer types
68  Integer types having exactly the specified width */
69 
70 /*@{*/
71 
72 /** \ingroup avr_stdint
73  8-bit signed type. */
74 
75 typedef signed char int8_t;
76 
77 /** \ingroup avr_stdint
78  8-bit unsigned type. */
79 
80 typedef unsigned char uint8_t;
81 
82 /** \ingroup avr_stdint
83  16-bit signed type. */
84 
85 typedef signed int int16_t;
86 
87 /** \ingroup avr_stdint
88  16-bit unsigned type. */
89 
90 typedef unsigned int uint16_t;
91 
92 /** \ingroup avr_stdint
93  32-bit signed type. */
94 
95 typedef signed long int int32_t;
96 
97 /** \ingroup avr_stdint
98  32-bit unsigned type. */
99 
100 typedef unsigned long int uint32_t;
101 
102 /** \ingroup avr_stdint
103  64-bit signed type.
104  \note This type is not available when the compiler
105  option -mint8 is in effect. */
106 
107 typedef signed long long int int64_t;
108 
109 /** \ingroup avr_stdint
110  64-bit unsigned type.
111  \note This type is not available when the compiler
112  option -mint8 is in effect. */
113 
114 typedef unsigned long long int uint64_t;
115 
116 /*@}*/
117 
118 #else /* !defined(__DOXYGEN__) */
119 
120 /* actual implementation goes here */
121 
122 typedef signed int int8_t __attribute__((__mode__(__QI__)));
123 typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
124 typedef signed int int16_t __attribute__ ((__mode__ (__HI__)));
125 typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
126 typedef signed int int32_t __attribute__ ((__mode__ (__SI__)));
127 typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
128 #if !__USING_MINT8
129 typedef signed int int64_t __attribute__((__mode__(__DI__)));
130 typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
131 #endif
132 
133 #endif /* defined(__DOXYGEN__) */
134 
135 /** \name Integer types capable of holding object pointers
136  These allow you to declare variables of the same size as a pointer. */
137 
138 /*@{*/
139 
140 /** \ingroup avr_stdint
141  Signed pointer compatible type. */
142 
144 
145 /** \ingroup avr_stdint
146  Unsigned pointer compatible type. */
147 
149 
150 /*@}*/
151 
152 /** \name Minimum-width integer types
153  Integer types having at least the specified width */
154 
155 /*@{*/
156 
157 /** \ingroup avr_stdint
158  signed int with at least 8 bits. */
159 
161 
162 /** \ingroup avr_stdint
163  unsigned int with at least 8 bits. */
164 
166 
167 /** \ingroup avr_stdint
168  signed int with at least 16 bits. */
169 
171 
172 /** \ingroup avr_stdint
173  unsigned int with at least 16 bits. */
174 
176 
177 /** \ingroup avr_stdint
178  signed int with at least 32 bits. */
179 
181 
182 /** \ingroup avr_stdint
183  unsigned int with at least 32 bits. */
184 
186 
187 #if !__USING_MINT8 || defined(__DOXYGEN__)
188 /** \ingroup avr_stdint
189  signed int with at least 64 bits.
190  \note This type is not available when the compiler
191  option -mint8 is in effect. */
192 
194 
195 /** \ingroup avr_stdint
196  unsigned int with at least 64 bits.
197  \note This type is not available when the compiler
198  option -mint8 is in effect. */
199 
201 #endif
202 
203 /*@}*/
204 
205 
206 /** \name Fastest minimum-width integer types
207  Integer types being usually fastest having at least the specified width */
208 
209 /*@{*/
210 
211 /** \ingroup avr_stdint
212  fastest signed int with at least 8 bits. */
213 
215 
216 /** \ingroup avr_stdint
217  fastest unsigned int with at least 8 bits. */
218 
220 
221 /** \ingroup avr_stdint
222  fastest signed int with at least 16 bits. */
223 
225 
226 /** \ingroup avr_stdint
227  fastest unsigned int with at least 16 bits. */
228 
230 
231 /** \ingroup avr_stdint
232  fastest signed int with at least 32 bits. */
233 
235 
236 /** \ingroup avr_stdint
237  fastest unsigned int with at least 32 bits. */
238 
240 
241 #if !__USING_MINT8 || defined(__DOXYGEN__)
242 /** \ingroup avr_stdint
243  fastest signed int with at least 64 bits.
244  \note This type is not available when the compiler
245  option -mint8 is in effect. */
246 
248 
249 /** \ingroup avr_stdint
250  fastest unsigned int with at least 64 bits.
251  \note This type is not available when the compiler
252  option -mint8 is in effect. */
253 
255 #endif
256 
257 /*@}*/
258 
259 
260 /** \name Greatest-width integer types
261  Types designating integer data capable of representing any value of
262  any integer type in the corresponding signed or unsigned category */
263 
264 /*@{*/
265 
266 #if __USING_MINT8
267 typedef int32_t intmax_t;
268 
269 typedef uint32_t uintmax_t;
270 #else /* !__USING_MINT8 */
271 /** \ingroup avr_stdint
272  largest signed int available. */
273 
275 
276 /** \ingroup avr_stdint
277  largest unsigned int available. */
278 
280 #endif /* __USING_MINT8 */
281 
282 /*@}*/
283 
284 /* Helping macro */
285 #ifndef __CONCAT
286 #define __CONCATenate(left, right) left ## right
287 #define __CONCAT(left, right) __CONCATenate(left, right)
288 #endif
289 
290 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
291 
292 /** \name Limits of specified-width integer types
293  C++ implementations should define these macros only when
294  __STDC_LIMIT_MACROS is defined before <stdint.h> is included */
295 
296 /*@{*/
297 
298 /** \ingroup avr_stdint
299  largest positive value an int8_t can hold. */
300 
301 #define INT8_MAX 0x7f
302 
303 /** \ingroup avr_stdint
304  smallest negative value an int8_t can hold. */
305 
306 #define INT8_MIN (-INT8_MAX - 1)
307 
308 #if __USING_MINT8
309 
310 #define UINT8_MAX (__CONCAT(INT8_MAX, U) * 2U + 1U)
311 
312 #define INT16_MAX 0x7fffL
313 #define INT16_MIN (-INT16_MAX - 1L)
314 #define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2UL + 1UL)
315 
316 #define INT32_MAX 0x7fffffffLL
317 #define INT32_MIN (-INT32_MAX - 1LL)
318 #define UINT32_MAX (__CONCAT(INT32_MAX, U) * 2ULL + 1ULL)
319 
320 #else /* !__USING_MINT8 */
321 
322 /** \ingroup avr_stdint
323  largest value an uint8_t can hold. */
324 
325 #define UINT8_MAX (INT8_MAX * 2 + 1)
326 
327 /** \ingroup avr_stdint
328  largest positive value an int16_t can hold. */
329 
330 #define INT16_MAX 0x7fff
331 
332 /** \ingroup avr_stdint
333  smallest negative value an int16_t can hold. */
334 
335 #define INT16_MIN (-INT16_MAX - 1)
336 
337 /** \ingroup avr_stdint
338  largest value an uint16_t can hold. */
339 
340 #define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2U + 1U)
341 
342 /** \ingroup avr_stdint
343  largest positive value an int32_t can hold. */
344 
345 #define INT32_MAX 0x7fffffffL
346 
347 /** \ingroup avr_stdint
348  smallest negative value an int32_t can hold. */
349 
350 #define INT32_MIN (-INT32_MAX - 1L)
351 
352 /** \ingroup avr_stdint
353  largest value an uint32_t can hold. */
354 
355 #define UINT32_MAX (__CONCAT(INT32_MAX, U) * 2UL + 1UL)
356 
357 #endif /* __USING_MINT8 */
358 
359 /** \ingroup avr_stdint
360  largest positive value an int64_t can hold. */
361 
362 #define INT64_MAX 0x7fffffffffffffffLL
363 
364 /** \ingroup avr_stdint
365  smallest negative value an int64_t can hold. */
366 
367 #define INT64_MIN (-INT64_MAX - 1LL)
368 
369 /** \ingroup avr_stdint
370  largest value an uint64_t can hold. */
371 
372 #define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL)
373 
374 /*@}*/
375 
376 /** \name Limits of minimum-width integer types */
377 /*@{*/
378 
379 /** \ingroup avr_stdint
380  largest positive value an int_least8_t can hold. */
381 
382 #define INT_LEAST8_MAX INT8_MAX
383 
384 /** \ingroup avr_stdint
385  smallest negative value an int_least8_t can hold. */
386 
387 #define INT_LEAST8_MIN INT8_MIN
388 
389 /** \ingroup avr_stdint
390  largest value an uint_least8_t can hold. */
391 
392 #define UINT_LEAST8_MAX UINT8_MAX
393 
394 /** \ingroup avr_stdint
395  largest positive value an int_least16_t can hold. */
396 
397 #define INT_LEAST16_MAX INT16_MAX
398 
399 /** \ingroup avr_stdint
400  smallest negative value an int_least16_t can hold. */
401 
402 #define INT_LEAST16_MIN INT16_MIN
403 
404 /** \ingroup avr_stdint
405  largest value an uint_least16_t can hold. */
406 
407 #define UINT_LEAST16_MAX UINT16_MAX
408 
409 /** \ingroup avr_stdint
410  largest positive value an int_least32_t can hold. */
411 
412 #define INT_LEAST32_MAX INT32_MAX
413 
414 /** \ingroup avr_stdint
415  smallest negative value an int_least32_t can hold. */
416 
417 #define INT_LEAST32_MIN INT32_MIN
418 
419 /** \ingroup avr_stdint
420  largest value an uint_least32_t can hold. */
421 
422 #define UINT_LEAST32_MAX UINT32_MAX
423 
424 /** \ingroup avr_stdint
425  largest positive value an int_least64_t can hold. */
426 
427 #define INT_LEAST64_MAX INT64_MAX
428 
429 /** \ingroup avr_stdint
430  smallest negative value an int_least64_t can hold. */
431 
432 #define INT_LEAST64_MIN INT64_MIN
433 
434 /** \ingroup avr_stdint
435  largest value an uint_least64_t can hold. */
436 
437 #define UINT_LEAST64_MAX UINT64_MAX
438 
439 /*@}*/
440 
441 /** \name Limits of fastest minimum-width integer types */
442 
443 /*@{*/
444 
445 /** \ingroup avr_stdint
446  largest positive value an int_fast8_t can hold. */
447 
448 #define INT_FAST8_MAX INT8_MAX
449 
450 /** \ingroup avr_stdint
451  smallest negative value an int_fast8_t can hold. */
452 
453 #define INT_FAST8_MIN INT8_MIN
454 
455 /** \ingroup avr_stdint
456  largest value an uint_fast8_t can hold. */
457 
458 #define UINT_FAST8_MAX UINT8_MAX
459 
460 /** \ingroup avr_stdint
461  largest positive value an int_fast16_t can hold. */
462 
463 #define INT_FAST16_MAX INT16_MAX
464 
465 /** \ingroup avr_stdint
466  smallest negative value an int_fast16_t can hold. */
467 
468 #define INT_FAST16_MIN INT16_MIN
469 
470 /** \ingroup avr_stdint
471  largest value an uint_fast16_t can hold. */
472 
473 #define UINT_FAST16_MAX UINT16_MAX
474 
475 /** \ingroup avr_stdint
476  largest positive value an int_fast32_t can hold. */
477 
478 #define INT_FAST32_MAX INT32_MAX
479 
480 /** \ingroup avr_stdint
481  smallest negative value an int_fast32_t can hold. */
482 
483 #define INT_FAST32_MIN INT32_MIN
484 
485 /** \ingroup avr_stdint
486  largest value an uint_fast32_t can hold. */
487 
488 #define UINT_FAST32_MAX UINT32_MAX
489 
490 /** \ingroup avr_stdint
491  largest positive value an int_fast64_t can hold. */
492 
493 #define INT_FAST64_MAX INT64_MAX
494 
495 /** \ingroup avr_stdint
496  smallest negative value an int_fast64_t can hold. */
497 
498 #define INT_FAST64_MIN INT64_MIN
499 
500 /** \ingroup avr_stdint
501  largest value an uint_fast64_t can hold. */
502 
503 #define UINT_FAST64_MAX UINT64_MAX
504 
505 /*@}*/
506 
507 /** \name Limits of integer types capable of holding object pointers */
508 
509 /*@{*/
510 
511 /** \ingroup avr_stdint
512  largest positive value an intptr_t can hold. */
513 
514 #define INTPTR_MAX INT16_MAX
515 
516 /** \ingroup avr_stdint
517  smallest negative value an intptr_t can hold. */
518 
519 #define INTPTR_MIN INT16_MIN
520 
521 /** \ingroup avr_stdint
522  largest value an uintptr_t can hold. */
523 
524 #define UINTPTR_MAX UINT16_MAX
525 
526 /*@}*/
527 
528 /** \name Limits of greatest-width integer types */
529 
530 /*@{*/
531 
532 /** \ingroup avr_stdint
533  largest positive value an intmax_t can hold. */
534 
535 #define INTMAX_MAX INT64_MAX
536 
537 /** \ingroup avr_stdint
538  smallest negative value an intmax_t can hold. */
539 
540 #define INTMAX_MIN INT64_MIN
541 
542 /** \ingroup avr_stdint
543  largest value an uintmax_t can hold. */
544 
545 #define UINTMAX_MAX UINT64_MAX
546 
547 /*@}*/
548 
549 /** \name Limits of other integer types
550  C++ implementations should define these macros only when
551  __STDC_LIMIT_MACROS is defined before <stdint.h> is included */
552 
553 /*@{*/
554 
555 /** \ingroup avr_stdint
556  largest positive value a ptrdiff_t can hold. */
557 
558 #define PTRDIFF_MAX INT16_MAX
559 
560 /** \ingroup avr_stdint
561  smallest negative value a ptrdiff_t can hold. */
562 
563 #define PTRDIFF_MIN INT16_MIN
564 
565 
566 /* Limits of sig_atomic_t */
567 /* signal.h is currently not implemented (not avr/signal.h) */
568 
569 /** \ingroup avr_stdint
570  largest positive value a sig_atomic_t can hold. */
571 
572 #define SIG_ATOMIC_MAX INT8_MAX
573 
574 /** \ingroup avr_stdint
575  smallest negative value a sig_atomic_t can hold. */
576 
577 #define SIG_ATOMIC_MIN INT8_MIN
578 
579 
580 /** \ingroup avr_stdint
581  largest value a size_t can hold. */
582 
583 #define SIZE_MAX UINT16_MAX
584 
585 
586 /* Limits of wchar_t */
587 /* wchar.h is currently not implemented */
588 /* #define WCHAR_MAX */
589 /* #define WCHAR_MIN */
590 
591 
592 /* Limits of wint_t */
593 /* wchar.h is currently not implemented */
594 #ifndef WCHAR_MAX
595 #define WCHAR_MAX __WCHAR_MAX__
596 #define WCHAR_MIN __WCHAR_MIN__
597 #endif
598 #ifndef WINT_MAX
599 #define WINT_MAX __WINT_MAX__
600 #define WINT_MIN __WINT_MIN__
601 #endif
602 
603 
604 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
605 
606 #if (!defined __cplusplus || __cplusplus >= 201103L \
607  || defined __STDC_CONSTANT_MACROS)
608 
609 /** \name Macros for integer constants
610  C++ implementations should define these macros only when
611  __STDC_CONSTANT_MACROS is defined before <stdint.h> is included.
612 
613  These definitions are valid for integer constants without suffix and
614  for macros defined as integer constant without suffix */
615 
616 /* The GNU C preprocessor defines special macros in the implementation
617  namespace to allow a definition that works in #if expressions. */
618 #ifdef __INT8_C
619 #define INT8_C(c) __INT8_C(c)
620 #define INT16_C(c) __INT16_C(c)
621 #define INT32_C(c) __INT32_C(c)
622 #define INT64_C(c) __INT64_C(c)
623 #define UINT8_C(c) __UINT8_C(c)
624 #define UINT16_C(c) __UINT16_C(c)
625 #define UINT32_C(c) __UINT32_C(c)
626 #define UINT64_C(c) __UINT64_C(c)
627 #define INTMAX_C(c) __INTMAX_C(c)
628 #define UINTMAX_C(c) __UINTMAX_C(c)
629 #else
630 /** \ingroup avr_stdint
631  define a constant of type int8_t */
632 
633 #define INT8_C(value) ((int8_t) value)
634 
635 /** \ingroup avr_stdint
636  define a constant of type uint8_t */
637 
638 #define UINT8_C(value) ((uint8_t) __CONCAT(value, U))
639 
640 #if __USING_MINT8
641 
642 #define INT16_C(value) __CONCAT(value, L)
643 #define UINT16_C(value) __CONCAT(value, UL)
644 
645 #define INT32_C(value) ((int32_t) __CONCAT(value, LL))
646 #define UINT32_C(value) ((uint32_t) __CONCAT(value, ULL))
647 
648 #else /* !__USING_MINT8 */
649 
650 /** \ingroup avr_stdint
651  define a constant of type int16_t */
652 
653 #define INT16_C(value) value
654 
655 /** \ingroup avr_stdint
656  define a constant of type uint16_t */
657 
658 #define UINT16_C(value) __CONCAT(value, U)
659 
660 /** \ingroup avr_stdint
661  define a constant of type int32_t */
662 
663 #define INT32_C(value) __CONCAT(value, L)
664 
665 /** \ingroup avr_stdint
666  define a constant of type uint32_t */
667 
668 #define UINT32_C(value) __CONCAT(value, UL)
669 
670 #endif /* __USING_MINT8 */
671 
672 /** \ingroup avr_stdint
673  define a constant of type int64_t */
674 
675 #define INT64_C(value) __CONCAT(value, LL)
676 
677 /** \ingroup avr_stdint
678  define a constant of type uint64_t */
679 
680 #define UINT64_C(value) __CONCAT(value, ULL)
681 
682 /** \ingroup avr_stdint
683  define a constant of type intmax_t */
684 
685 #define INTMAX_C(value) __CONCAT(value, LL)
686 
687 /** \ingroup avr_stdint
688  define a constant of type uintmax_t */
689 
690 #define UINTMAX_C(value) __CONCAT(value, ULL)
691 
692 #endif /* !__INT8_C */
693 
694 /*@}*/
695 
696 #endif /* (!defined __cplusplus || __cplusplus >= 201103L \
697  || defined __STDC_CONSTANT_MACROS) */
698 
699 
700 #endif /* _STDINT_H_ */
int16_t intptr_t
Definition: stdint.h:143
signed long long int int64_t
Definition: stdint.h:107
uint64_t uint_least64_t
Definition: stdint.h:200
uint64_t uint_fast64_t
Definition: stdint.h:254
int64_t int_fast64_t
Definition: stdint.h:247
int32_t int_fast32_t
Definition: stdint.h:234
signed int int16_t
Definition: stdint.h:85
signed char int8_t
Definition: stdint.h:75
uint64_t uintmax_t
Definition: stdint.h:279
int32_t int_least32_t
Definition: stdint.h:180
signed long int int32_t
Definition: stdint.h:95
int8_t int_least8_t
Definition: stdint.h:160
int64_t int_least64_t
Definition: stdint.h:193
int8_t int_fast8_t
Definition: stdint.h:214
uint16_t uint_fast16_t
Definition: stdint.h:229
uint16_t uintptr_t
Definition: stdint.h:148
unsigned char uint8_t
Definition: stdint.h:80
unsigned long int uint32_t
Definition: stdint.h:100
uint8_t uint_fast8_t
Definition: stdint.h:219
uint16_t uint_least16_t
Definition: stdint.h:175
uint32_t uint_fast32_t
Definition: stdint.h:239
uint32_t uint_least32_t
Definition: stdint.h:185
unsigned long long int uint64_t
Definition: stdint.h:114
int64_t intmax_t
Definition: stdint.h:274
uint8_t uint_least8_t
Definition: stdint.h:165
int16_t int_least16_t
Definition: stdint.h:170
unsigned int uint16_t
Definition: stdint.h:90
int16_t int_fast16_t
Definition: stdint.h:224

Automatically generated by Doxygen 1.8.7 on Tue Aug 12 2014.