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

Automatically generated by Doxygen 1.8.3.1 on Sun Sep 29 2013.