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.
00001 /* Copyright (c) 2002,2004,2005 Marek Michalkiewicz
00002    Copyright (c) 2005, Carlos Lamas
00003    Copyright (c) 2005,2007 Joerg Wunsch
00004    All rights reserved.
00005 
00006    Redistribution and use in source and binary forms, with or without
00007    modification, are permitted provided that the following conditions are met:
00008 
00009    * Redistributions of source code must retain the above copyright
00010      notice, this list of conditions and the following disclaimer.
00011 
00012    * Redistributions in binary form must reproduce the above copyright
00013      notice, this list of conditions and the following disclaimer in
00014      the documentation and/or other materials provided with the
00015      distribution.
00016 
00017    * Neither the name of the copyright holders nor the names of
00018      contributors may be used to endorse or promote products derived
00019      from this software without specific prior written permission.
00020 
00021   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00025   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00026   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00027   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00030   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031   POSSIBILITY OF SUCH DAMAGE. */
00032 
00033 /* $Id: stdint_8h_source.html,v 1.1.1.4 2012/01/03 16:04:22 joerg_wunsch Exp $ */
00034 
00035 /*
00036  * ISO/IEC 9899:1999  7.18 Integer types <stdint.h>
00037  */
00038 
00039 #ifndef __STDINT_H_
00040 #define __STDINT_H_
00041 
00042 /** \file */
00043 /** \defgroup avr_stdint <stdint.h>: Standard Integer Types
00044     \code #include <stdint.h> \endcode
00045 
00046     Use [u]intN_t if you need exactly N bits.
00047 
00048     Since these typedefs are mandated by the C99 standard, they are preferred
00049     over rolling your own typedefs.  */
00050 
00051 /*
00052  * __USING_MINT8 is defined to 1 if the -mint8 option is in effect.
00053  */
00054 #if __INT_MAX__ == 127
00055 # define __USING_MINT8 1
00056 #else
00057 # define __USING_MINT8 0
00058 #endif
00059 
00060 /* Integer types */
00061 
00062 #if defined(__DOXYGEN__)
00063 
00064 /* doxygen gets confused by the __attribute__ stuff */
00065 
00066 /** \name Exact-width integer types
00067     Integer types having exactly the specified width */
00068 
00069 /*@{*/
00070 
00071 /** \ingroup avr_stdint
00072     8-bit signed type. */
00073 
00074 typedef signed char int8_t;
00075 
00076 /** \ingroup avr_stdint
00077     8-bit unsigned type. */
00078 
00079 typedef unsigned char uint8_t;
00080 
00081 /** \ingroup avr_stdint
00082     16-bit signed type. */
00083 
00084 typedef signed int int16_t;
00085 
00086 /** \ingroup avr_stdint
00087     16-bit unsigned type. */
00088 
00089 typedef unsigned int uint16_t;
00090 
00091 /** \ingroup avr_stdint
00092     32-bit signed type. */
00093 
00094 typedef signed long int int32_t;
00095 
00096 /** \ingroup avr_stdint
00097     32-bit unsigned type. */
00098 
00099 typedef unsigned long int uint32_t;
00100 
00101 /** \ingroup avr_stdint
00102     64-bit signed type.
00103     \note This type is not available when the compiler
00104     option -mint8 is in effect. */
00105 
00106 typedef signed long long int int64_t;
00107 
00108 /** \ingroup avr_stdint
00109     64-bit unsigned type.
00110     \note This type is not available when the compiler
00111     option -mint8 is in effect. */
00112 
00113 typedef unsigned long long int uint64_t;
00114 
00115 /*@}*/
00116 
00117 #else /* !defined(__DOXYGEN__) */
00118 
00119 /* actual implementation goes here */
00120 
00121 typedef signed int int8_t __attribute__((__mode__(__QI__)));
00122 typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
00123 typedef signed int int16_t __attribute__ ((__mode__ (__HI__)));
00124 typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
00125 typedef signed int int32_t __attribute__ ((__mode__ (__SI__)));
00126 typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
00127 #if !__USING_MINT8
00128 typedef signed int int64_t __attribute__((__mode__(__DI__)));
00129 typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
00130 #endif
00131 
00132 #endif /* defined(__DOXYGEN__) */
00133 
00134 /** \name Integer types capable of holding object pointers
00135     These allow you to declare variables of the same size as a pointer. */
00136 
00137 /*@{*/
00138 
00139 /** \ingroup avr_stdint
00140     Signed pointer compatible type. */
00141 
00142 typedef int16_t intptr_t;
00143 
00144 /** \ingroup avr_stdint
00145     Unsigned pointer compatible type. */
00146 
00147 typedef uint16_t uintptr_t;
00148 
00149 /*@}*/
00150 
00151 /** \name Minimum-width integer types
00152    Integer types having at least the specified width */
00153 
00154 /*@{*/
00155 
00156 /** \ingroup avr_stdint
00157     signed int with at least 8 bits. */
00158 
00159 typedef int8_t   int_least8_t;
00160 
00161 /** \ingroup avr_stdint
00162     unsigned int with at least 8 bits. */
00163 
00164 typedef uint8_t  uint_least8_t;
00165 
00166 /** \ingroup avr_stdint
00167     signed int with at least 16 bits. */
00168 
00169 typedef int16_t  int_least16_t;
00170 
00171 /** \ingroup avr_stdint
00172     unsigned int with at least 16 bits. */
00173 
00174 typedef uint16_t uint_least16_t;
00175 
00176 /** \ingroup avr_stdint
00177     signed int with at least 32 bits. */
00178 
00179 typedef int32_t  int_least32_t;
00180 
00181 /** \ingroup avr_stdint
00182     unsigned int with at least 32 bits. */
00183 
00184 typedef uint32_t uint_least32_t;
00185 
00186 #if !__USING_MINT8 || defined(__DOXYGEN__)
00187 /** \ingroup avr_stdint
00188     signed int with at least 64 bits.
00189     \note This type is not available when the compiler
00190     option -mint8 is in effect. */
00191 
00192 typedef int64_t  int_least64_t;
00193 
00194 /** \ingroup avr_stdint
00195     unsigned int with at least 64 bits.
00196     \note This type is not available when the compiler
00197     option -mint8 is in effect. */
00198 
00199 typedef uint64_t uint_least64_t;
00200 #endif
00201 
00202 /*@}*/
00203 
00204 
00205 /** \name Fastest minimum-width integer types
00206    Integer types being usually fastest having at least the specified width */
00207 
00208 /*@{*/
00209 
00210 /** \ingroup avr_stdint
00211     fastest signed int with at least 8 bits. */
00212 
00213 typedef int8_t int_fast8_t;
00214 
00215 /** \ingroup avr_stdint
00216     fastest unsigned int with at least 8 bits. */
00217 
00218 typedef uint8_t uint_fast8_t;
00219 
00220 /** \ingroup avr_stdint
00221     fastest signed int with at least 16 bits. */
00222 
00223 typedef int16_t int_fast16_t;
00224 
00225 /** \ingroup avr_stdint
00226     fastest unsigned int with at least 16 bits. */
00227 
00228 typedef uint16_t uint_fast16_t;
00229 
00230 /** \ingroup avr_stdint
00231     fastest signed int with at least 32 bits. */
00232 
00233 typedef int32_t int_fast32_t;
00234 
00235 /** \ingroup avr_stdint
00236     fastest unsigned int with at least 32 bits. */
00237 
00238 typedef uint32_t uint_fast32_t;
00239 
00240 #if !__USING_MINT8 || defined(__DOXYGEN__)
00241 /** \ingroup avr_stdint
00242     fastest signed int with at least 64 bits.
00243     \note This type is not available when the compiler
00244     option -mint8 is in effect. */
00245 
00246 typedef int64_t int_fast64_t;
00247 
00248 /** \ingroup avr_stdint
00249     fastest unsigned int with at least 64 bits.
00250     \note This type is not available when the compiler
00251     option -mint8 is in effect. */
00252 
00253 typedef uint64_t uint_fast64_t;
00254 #endif
00255 
00256 /*@}*/
00257 
00258 
00259 /** \name Greatest-width integer types
00260    Types designating integer data capable of representing any value of
00261    any integer type in the corresponding signed or unsigned category */
00262 
00263 /*@{*/
00264 
00265 #if __USING_MINT8
00266 typedef int32_t intmax_t;
00267 
00268 typedef uint32_t uintmax_t;
00269 #else  /* !__USING_MINT8 */
00270 /** \ingroup avr_stdint
00271     largest signed int available. */
00272 
00273 typedef int64_t intmax_t;
00274 
00275 /** \ingroup avr_stdint
00276     largest unsigned int available. */
00277 
00278 typedef uint64_t uintmax_t;
00279 #endif /* __USING_MINT8 */
00280 
00281 /*@}*/
00282 
00283 /* Helping macro */
00284 #ifndef __CONCAT
00285 #define __CONCATenate(left, right) left ## right
00286 #define __CONCAT(left, right) __CONCATenate(left, right)
00287 #endif
00288 
00289 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
00290 
00291 /** \name Limits of specified-width integer types
00292    C++ implementations should define these macros only when
00293    __STDC_LIMIT_MACROS is defined before <stdint.h> is included */
00294 
00295 /*@{*/
00296 
00297 /** \ingroup avr_stdint
00298     largest positive value an int8_t can hold. */
00299 
00300 #define INT8_MAX 0x7f
00301 
00302 /** \ingroup avr_stdint
00303     smallest negative value an int8_t can hold. */
00304 
00305 #define INT8_MIN (-INT8_MAX - 1)
00306 
00307 /** \ingroup avr_stdint
00308     largest value an uint8_t can hold. */
00309 
00310 #define UINT8_MAX (__CONCAT(INT8_MAX, U) * 2U + 1U)
00311 
00312 #if __USING_MINT8
00313 
00314 #define INT16_MAX 0x7fffL
00315 #define INT16_MIN (-INT16_MAX - 1L)
00316 #define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2UL + 1UL)
00317 
00318 #define INT32_MAX 0x7fffffffLL
00319 #define INT32_MIN (-INT32_MAX - 1LL)
00320 #define UINT32_MAX (__CONCAT(INT32_MAX, U) * 2ULL + 1ULL)
00321 
00322 #else /* !__USING_MINT8 */
00323 
00324 /** \ingroup avr_stdint
00325     largest positive value an int16_t can hold. */
00326 
00327 #define INT16_MAX 0x7fff
00328 
00329 /** \ingroup avr_stdint
00330     smallest negative value an int16_t can hold. */
00331 
00332 #define INT16_MIN (-INT16_MAX - 1)
00333 
00334 /** \ingroup avr_stdint
00335     largest value an uint16_t can hold. */
00336 
00337 #define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2U + 1U)
00338 
00339 /** \ingroup avr_stdint
00340     largest positive value an int32_t can hold. */
00341 
00342 #define INT32_MAX 0x7fffffffL
00343 
00344 /** \ingroup avr_stdint
00345     smallest negative value an int32_t can hold. */
00346 
00347 #define INT32_MIN (-INT32_MAX - 1L)
00348 
00349 /** \ingroup avr_stdint
00350     largest value an uint32_t can hold. */
00351 
00352 #define UINT32_MAX (__CONCAT(INT32_MAX, U) * 2UL + 1UL)
00353 
00354 #endif /* __USING_MINT8 */
00355 
00356 /** \ingroup avr_stdint
00357     largest positive value an int64_t can hold. */
00358 
00359 #define INT64_MAX 0x7fffffffffffffffLL
00360 
00361 /** \ingroup avr_stdint
00362     smallest negative value an int64_t can hold. */
00363 
00364 #define INT64_MIN (-INT64_MAX - 1LL)
00365 
00366 /** \ingroup avr_stdint
00367     largest value an uint64_t can hold. */
00368 
00369 #define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL)
00370 
00371 /*@}*/
00372 
00373 /** \name Limits of minimum-width integer types */
00374 /*@{*/
00375 
00376 /** \ingroup avr_stdint
00377     largest positive value an int_least8_t can hold. */
00378 
00379 #define INT_LEAST8_MAX INT8_MAX
00380 
00381 /** \ingroup avr_stdint
00382     smallest negative value an int_least8_t can hold. */
00383 
00384 #define INT_LEAST8_MIN INT8_MIN
00385 
00386 /** \ingroup avr_stdint
00387     largest value an uint_least8_t can hold. */
00388 
00389 #define UINT_LEAST8_MAX UINT8_MAX
00390 
00391 /** \ingroup avr_stdint
00392     largest positive value an int_least16_t can hold. */
00393 
00394 #define INT_LEAST16_MAX INT16_MAX
00395 
00396 /** \ingroup avr_stdint
00397     smallest negative value an int_least16_t can hold. */
00398 
00399 #define INT_LEAST16_MIN INT16_MIN
00400 
00401 /** \ingroup avr_stdint
00402     largest value an uint_least16_t can hold. */
00403 
00404 #define UINT_LEAST16_MAX UINT16_MAX
00405 
00406 /** \ingroup avr_stdint
00407     largest positive value an int_least32_t can hold. */
00408 
00409 #define INT_LEAST32_MAX INT32_MAX
00410 
00411 /** \ingroup avr_stdint
00412     smallest negative value an int_least32_t can hold. */
00413 
00414 #define INT_LEAST32_MIN INT32_MIN
00415 
00416 /** \ingroup avr_stdint
00417     largest value an uint_least32_t can hold. */
00418 
00419 #define UINT_LEAST32_MAX UINT32_MAX
00420 
00421 /** \ingroup avr_stdint
00422     largest positive value an int_least64_t can hold. */
00423 
00424 #define INT_LEAST64_MAX INT64_MAX
00425 
00426 /** \ingroup avr_stdint
00427     smallest negative value an int_least64_t can hold. */
00428 
00429 #define INT_LEAST64_MIN INT64_MIN
00430 
00431 /** \ingroup avr_stdint
00432     largest value an uint_least64_t can hold. */
00433 
00434 #define UINT_LEAST64_MAX UINT64_MAX
00435 
00436 /*@}*/
00437 
00438 /** \name Limits of fastest minimum-width integer types */
00439 
00440 /*@{*/
00441 
00442 /** \ingroup avr_stdint
00443     largest positive value an int_fast8_t can hold. */
00444 
00445 #define INT_FAST8_MAX INT8_MAX
00446 
00447 /** \ingroup avr_stdint
00448     smallest negative value an int_fast8_t can hold. */
00449 
00450 #define INT_FAST8_MIN INT8_MIN
00451 
00452 /** \ingroup avr_stdint
00453     largest value an uint_fast8_t can hold. */
00454 
00455 #define UINT_FAST8_MAX UINT8_MAX
00456 
00457 /** \ingroup avr_stdint
00458     largest positive value an int_fast16_t can hold. */
00459 
00460 #define INT_FAST16_MAX INT16_MAX
00461 
00462 /** \ingroup avr_stdint
00463     smallest negative value an int_fast16_t can hold. */
00464 
00465 #define INT_FAST16_MIN INT16_MIN
00466 
00467 /** \ingroup avr_stdint
00468     largest value an uint_fast16_t can hold. */
00469 
00470 #define UINT_FAST16_MAX UINT16_MAX
00471 
00472 /** \ingroup avr_stdint
00473     largest positive value an int_fast32_t can hold. */
00474 
00475 #define INT_FAST32_MAX INT32_MAX
00476 
00477 /** \ingroup avr_stdint
00478     smallest negative value an int_fast32_t can hold. */
00479 
00480 #define INT_FAST32_MIN INT32_MIN
00481 
00482 /** \ingroup avr_stdint
00483     largest value an uint_fast32_t can hold. */
00484 
00485 #define UINT_FAST32_MAX UINT32_MAX
00486 
00487 /** \ingroup avr_stdint
00488     largest positive value an int_fast64_t can hold. */
00489 
00490 #define INT_FAST64_MAX INT64_MAX
00491 
00492 /** \ingroup avr_stdint
00493     smallest negative value an int_fast64_t can hold. */
00494 
00495 #define INT_FAST64_MIN INT64_MIN
00496 
00497 /** \ingroup avr_stdint
00498     largest value an uint_fast64_t can hold. */
00499 
00500 #define UINT_FAST64_MAX UINT64_MAX
00501 
00502 /*@}*/
00503 
00504 /** \name Limits of integer types capable of holding object pointers */
00505 
00506 /*@{*/
00507 
00508 /** \ingroup avr_stdint
00509     largest positive value an intptr_t can hold. */
00510 
00511 #define INTPTR_MAX INT16_MAX
00512 
00513 /** \ingroup avr_stdint
00514     smallest negative value an intptr_t can hold. */
00515 
00516 #define INTPTR_MIN INT16_MIN
00517 
00518 /** \ingroup avr_stdint
00519     largest value an uintptr_t can hold. */
00520 
00521 #define UINTPTR_MAX UINT16_MAX
00522 
00523 /*@}*/
00524 
00525 /** \name Limits of greatest-width integer types */
00526 
00527 /*@{*/
00528 
00529 /** \ingroup avr_stdint
00530     largest positive value an intmax_t can hold. */
00531 
00532 #define INTMAX_MAX INT64_MAX
00533 
00534 /** \ingroup avr_stdint
00535     smallest negative value an intmax_t can hold. */
00536 
00537 #define INTMAX_MIN INT64_MIN
00538 
00539 /** \ingroup avr_stdint
00540     largest value an uintmax_t can hold. */
00541 
00542 #define UINTMAX_MAX UINT64_MAX
00543 
00544 /*@}*/
00545 
00546 /** \name Limits of other integer types
00547     C++ implementations should define these macros only when
00548     __STDC_LIMIT_MACROS is defined before <stdint.h> is included */
00549 
00550 /*@{*/
00551 
00552 /** \ingroup avr_stdint
00553     largest positive value a ptrdiff_t can hold. */
00554 
00555 #define PTRDIFF_MAX INT16_MAX
00556 
00557 /** \ingroup avr_stdint
00558     smallest negative value a ptrdiff_t can hold. */
00559 
00560 #define PTRDIFF_MIN INT16_MIN
00561 
00562 
00563 /* Limits of sig_atomic_t */
00564 /* signal.h is currently not implemented (not avr/signal.h) */
00565 
00566 /** \ingroup avr_stdint
00567     largest positive value a sig_atomic_t can hold. */
00568 
00569 #define SIG_ATOMIC_MAX INT8_MAX
00570 
00571 /** \ingroup avr_stdint
00572     smallest negative value a sig_atomic_t can hold. */
00573 
00574 #define SIG_ATOMIC_MIN INT8_MIN
00575 
00576 
00577 /** \ingroup avr_stdint
00578     largest value a size_t can hold. */
00579 
00580 #define SIZE_MAX (__CONCAT(INT16_MAX, U))
00581 
00582 
00583 /* Limits of wchar_t */
00584 /* wchar.h is currently not implemented */
00585 /* #define WCHAR_MAX */
00586 /* #define WCHAR_MIN */
00587 
00588 
00589 /* Limits of wint_t */
00590 /* wchar.h is currently not implemented */
00591 /* #define WINT_MAX */
00592 /* #define WINT_MIN */
00593 
00594 
00595 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
00596 
00597 #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
00598 
00599 /** \name Macros for integer constants
00600     C++ implementations should define these macros only when
00601     __STDC_CONSTANT_MACROS is defined before <stdint.h> is included.
00602 
00603     These definitions are valid for integer constants without suffix and
00604     for macros defined as integer constant without suffix */
00605 
00606 /** \ingroup avr_stdint
00607     define a constant of type int8_t */
00608 
00609 #define INT8_C(value) ((int8_t) value)
00610 
00611 /** \ingroup avr_stdint
00612     define a constant of type uint8_t */
00613 
00614 #define UINT8_C(value) ((uint8_t) __CONCAT(value, U))
00615 
00616 #if __USING_MINT8
00617 
00618 #define INT16_C(value) __CONCAT(value, L)
00619 #define UINT16_C(value) __CONCAT(value, UL)
00620 
00621 #define INT32_C(value) ((int32_t) __CONCAT(value, LL))
00622 #define UINT32_C(value) ((uint32_t) __CONCAT(value, ULL))
00623 
00624 #else /* !__USING_MINT8 */
00625 
00626 /** \ingroup avr_stdint
00627     define a constant of type int16_t */
00628 
00629 #define INT16_C(value) value
00630 
00631 /** \ingroup avr_stdint
00632     define a constant of type uint16_t */
00633 
00634 #define UINT16_C(value) __CONCAT(value, U)
00635 
00636 /** \ingroup avr_stdint
00637     define a constant of type int32_t */
00638 
00639 #define INT32_C(value) __CONCAT(value, L)
00640 
00641 /** \ingroup avr_stdint
00642     define a constant of type uint32_t */
00643 
00644 #define UINT32_C(value) __CONCAT(value, UL)
00645 
00646 #endif /* __USING_MINT8 */
00647 
00648 /** \ingroup avr_stdint
00649     define a constant of type int64_t */
00650 
00651 #define INT64_C(value) __CONCAT(value, LL)
00652 
00653 /** \ingroup avr_stdint
00654     define a constant of type uint64_t */
00655 
00656 #define UINT64_C(value) __CONCAT(value, ULL)
00657 
00658 /** \ingroup avr_stdint
00659     define a constant of type intmax_t */
00660 
00661 #define INTMAX_C(value) __CONCAT(value, LL)
00662 
00663 /** \ingroup avr_stdint
00664     define a constant of type uintmax_t */
00665 
00666 #define UINTMAX_C(value) __CONCAT(value, ULL)
00667 
00668 /*@}*/
00669 
00670 #endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
00671 
00672 
00673 #endif /* _STDINT_H_ */

Automatically generated by Doxygen 1.7.6.1 on Tue Jan 3 2012.