avr-libc  2.0.0
Standard C library for AVR-GCC

AVR Libc Home Page

AVRs

AVR Libc Development Pages

Main Page

User Manual

Library Reference

FAQ

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