Back to index

glibc  2.9
inttypes.h
Go to the documentation of this file.
00001 /* Copyright (C) 1997-2001, 2004, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /*
00020  *     ISO C99: 7.8 Format conversion of integer types  <inttypes.h>
00021  */
00022 
00023 #ifndef _INTTYPES_H
00024 #define _INTTYPES_H  1
00025 
00026 #include <features.h>
00027 /* Get the type definitions.  */
00028 #include <stdint.h>
00029 
00030 /* Get a definition for wchar_t.  But we must not define wchar_t itself.  */
00031 #ifndef ____gwchar_t_defined
00032 # ifdef __cplusplus
00033 #  define __gwchar_t wchar_t
00034 # elif defined __WCHAR_TYPE__
00035 typedef __WCHAR_TYPE__ __gwchar_t;
00036 # else
00037 #  define __need_wchar_t
00038 #  include <stddef.h>
00039 typedef wchar_t __gwchar_t;
00040 # endif
00041 # define ____gwchar_t_defined      1
00042 #endif
00043 
00044 
00045 /* The ISO C99 standard specifies that these macros must only be
00046    defined if explicitly requested.  */
00047 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
00048 
00049 # if __WORDSIZE == 64
00050 #  define __PRI64_PREFIX    "l"
00051 #  define __PRIPTR_PREFIX   "l"
00052 # else
00053 #  define __PRI64_PREFIX    "ll"
00054 #  define __PRIPTR_PREFIX
00055 # endif
00056 
00057 /* Macros for printing format specifiers.  */
00058 
00059 /* Decimal notation.  */
00060 # define PRId8              "d"
00061 # define PRId16             "d"
00062 # define PRId32             "d"
00063 # define PRId64             __PRI64_PREFIX "d"
00064 
00065 # define PRIdLEAST8  "d"
00066 # define PRIdLEAST16 "d"
00067 # define PRIdLEAST32 "d"
00068 # define PRIdLEAST64 __PRI64_PREFIX "d"
00069 
00070 # define PRIdFAST8   "d"
00071 # define PRIdFAST16  __PRIPTR_PREFIX "d"
00072 # define PRIdFAST32  __PRIPTR_PREFIX "d"
00073 # define PRIdFAST64  __PRI64_PREFIX "d"
00074 
00075 
00076 # define PRIi8              "i"
00077 # define PRIi16             "i"
00078 # define PRIi32             "i"
00079 # define PRIi64             __PRI64_PREFIX "i"
00080 
00081 # define PRIiLEAST8  "i"
00082 # define PRIiLEAST16 "i"
00083 # define PRIiLEAST32 "i"
00084 # define PRIiLEAST64 __PRI64_PREFIX "i"
00085 
00086 # define PRIiFAST8   "i"
00087 # define PRIiFAST16  __PRIPTR_PREFIX "i"
00088 # define PRIiFAST32  __PRIPTR_PREFIX "i"
00089 # define PRIiFAST64  __PRI64_PREFIX "i"
00090 
00091 /* Octal notation.  */
00092 # define PRIo8              "o"
00093 # define PRIo16             "o"
00094 # define PRIo32             "o"
00095 # define PRIo64             __PRI64_PREFIX "o"
00096 
00097 # define PRIoLEAST8  "o"
00098 # define PRIoLEAST16 "o"
00099 # define PRIoLEAST32 "o"
00100 # define PRIoLEAST64 __PRI64_PREFIX "o"
00101 
00102 # define PRIoFAST8   "o"
00103 # define PRIoFAST16  __PRIPTR_PREFIX "o"
00104 # define PRIoFAST32  __PRIPTR_PREFIX "o"
00105 # define PRIoFAST64  __PRI64_PREFIX "o"
00106 
00107 /* Unsigned integers.  */
00108 # define PRIu8              "u"
00109 # define PRIu16             "u"
00110 # define PRIu32             "u"
00111 # define PRIu64             __PRI64_PREFIX "u"
00112 
00113 # define PRIuLEAST8  "u"
00114 # define PRIuLEAST16 "u"
00115 # define PRIuLEAST32 "u"
00116 # define PRIuLEAST64 __PRI64_PREFIX "u"
00117 
00118 # define PRIuFAST8   "u"
00119 # define PRIuFAST16  __PRIPTR_PREFIX "u"
00120 # define PRIuFAST32  __PRIPTR_PREFIX "u"
00121 # define PRIuFAST64  __PRI64_PREFIX "u"
00122 
00123 /* lowercase hexadecimal notation.  */
00124 # define PRIx8              "x"
00125 # define PRIx16             "x"
00126 # define PRIx32             "x"
00127 # define PRIx64             __PRI64_PREFIX "x"
00128 
00129 # define PRIxLEAST8  "x"
00130 # define PRIxLEAST16 "x"
00131 # define PRIxLEAST32 "x"
00132 # define PRIxLEAST64 __PRI64_PREFIX "x"
00133 
00134 # define PRIxFAST8   "x"
00135 # define PRIxFAST16  __PRIPTR_PREFIX "x"
00136 # define PRIxFAST32  __PRIPTR_PREFIX "x"
00137 # define PRIxFAST64  __PRI64_PREFIX "x"
00138 
00139 /* UPPERCASE hexadecimal notation.  */
00140 # define PRIX8              "X"
00141 # define PRIX16             "X"
00142 # define PRIX32             "X"
00143 # define PRIX64             __PRI64_PREFIX "X"
00144 
00145 # define PRIXLEAST8  "X"
00146 # define PRIXLEAST16 "X"
00147 # define PRIXLEAST32 "X"
00148 # define PRIXLEAST64 __PRI64_PREFIX "X"
00149 
00150 # define PRIXFAST8   "X"
00151 # define PRIXFAST16  __PRIPTR_PREFIX "X"
00152 # define PRIXFAST32  __PRIPTR_PREFIX "X"
00153 # define PRIXFAST64  __PRI64_PREFIX "X"
00154 
00155 
00156 /* Macros for printing `intmax_t' and `uintmax_t'.  */
00157 # define PRIdMAX     __PRI64_PREFIX "d"
00158 # define PRIiMAX     __PRI64_PREFIX "i"
00159 # define PRIoMAX     __PRI64_PREFIX "o"
00160 # define PRIuMAX     __PRI64_PREFIX "u"
00161 # define PRIxMAX     __PRI64_PREFIX "x"
00162 # define PRIXMAX     __PRI64_PREFIX "X"
00163 
00164 
00165 /* Macros for printing `intptr_t' and `uintptr_t'.  */
00166 # define PRIdPTR     __PRIPTR_PREFIX "d"
00167 # define PRIiPTR     __PRIPTR_PREFIX "i"
00168 # define PRIoPTR     __PRIPTR_PREFIX "o"
00169 # define PRIuPTR     __PRIPTR_PREFIX "u"
00170 # define PRIxPTR     __PRIPTR_PREFIX "x"
00171 # define PRIXPTR     __PRIPTR_PREFIX "X"
00172 
00173 
00174 /* Macros for scanning format specifiers.  */
00175 
00176 /* Signed decimal notation.  */
00177 # define SCNd8              "hhd"
00178 # define SCNd16             "hd"
00179 # define SCNd32             "d"
00180 # define SCNd64             __PRI64_PREFIX "d"
00181 
00182 # define SCNdLEAST8  "hhd"
00183 # define SCNdLEAST16 "hd"
00184 # define SCNdLEAST32 "d"
00185 # define SCNdLEAST64 __PRI64_PREFIX "d"
00186 
00187 # define SCNdFAST8   "hhd"
00188 # define SCNdFAST16  __PRIPTR_PREFIX "d"
00189 # define SCNdFAST32  __PRIPTR_PREFIX "d"
00190 # define SCNdFAST64  __PRI64_PREFIX "d"
00191 
00192 /* Signed decimal notation.  */
00193 # define SCNi8              "hhi"
00194 # define SCNi16             "hi"
00195 # define SCNi32             "i"
00196 # define SCNi64             __PRI64_PREFIX "i"
00197 
00198 # define SCNiLEAST8  "hhi"
00199 # define SCNiLEAST16 "hi"
00200 # define SCNiLEAST32 "i"
00201 # define SCNiLEAST64 __PRI64_PREFIX "i"
00202 
00203 # define SCNiFAST8   "hhi"
00204 # define SCNiFAST16  __PRIPTR_PREFIX "i"
00205 # define SCNiFAST32  __PRIPTR_PREFIX "i"
00206 # define SCNiFAST64  __PRI64_PREFIX "i"
00207 
00208 /* Unsigned decimal notation.  */
00209 # define SCNu8              "hhu"
00210 # define SCNu16             "hu"
00211 # define SCNu32             "u"
00212 # define SCNu64             __PRI64_PREFIX "u"
00213 
00214 # define SCNuLEAST8  "hhu"
00215 # define SCNuLEAST16 "hu"
00216 # define SCNuLEAST32 "u"
00217 # define SCNuLEAST64 __PRI64_PREFIX "u"
00218 
00219 # define SCNuFAST8   "hhu"
00220 # define SCNuFAST16  __PRIPTR_PREFIX "u"
00221 # define SCNuFAST32  __PRIPTR_PREFIX "u"
00222 # define SCNuFAST64  __PRI64_PREFIX "u"
00223 
00224 /* Octal notation.  */
00225 # define SCNo8              "hho"
00226 # define SCNo16             "ho"
00227 # define SCNo32             "o"
00228 # define SCNo64             __PRI64_PREFIX "o"
00229 
00230 # define SCNoLEAST8  "hho"
00231 # define SCNoLEAST16 "ho"
00232 # define SCNoLEAST32 "o"
00233 # define SCNoLEAST64 __PRI64_PREFIX "o"
00234 
00235 # define SCNoFAST8   "hho"
00236 # define SCNoFAST16  __PRIPTR_PREFIX "o"
00237 # define SCNoFAST32  __PRIPTR_PREFIX "o"
00238 # define SCNoFAST64  __PRI64_PREFIX "o"
00239 
00240 /* Hexadecimal notation.  */
00241 # define SCNx8              "hhx"
00242 # define SCNx16             "hx"
00243 # define SCNx32             "x"
00244 # define SCNx64             __PRI64_PREFIX "x"
00245 
00246 # define SCNxLEAST8  "hhx"
00247 # define SCNxLEAST16 "hx"
00248 # define SCNxLEAST32 "x"
00249 # define SCNxLEAST64 __PRI64_PREFIX "x"
00250 
00251 # define SCNxFAST8   "hhx"
00252 # define SCNxFAST16  __PRIPTR_PREFIX "x"
00253 # define SCNxFAST32  __PRIPTR_PREFIX "x"
00254 # define SCNxFAST64  __PRI64_PREFIX "x"
00255 
00256 
00257 /* Macros for scanning `intmax_t' and `uintmax_t'.  */
00258 # define SCNdMAX     __PRI64_PREFIX "d"
00259 # define SCNiMAX     __PRI64_PREFIX "i"
00260 # define SCNoMAX     __PRI64_PREFIX "o"
00261 # define SCNuMAX     __PRI64_PREFIX "u"
00262 # define SCNxMAX     __PRI64_PREFIX "x"
00263 
00264 /* Macros for scaning `intptr_t' and `uintptr_t'.  */
00265 # define SCNdPTR     __PRIPTR_PREFIX "d"
00266 # define SCNiPTR     __PRIPTR_PREFIX "i"
00267 # define SCNoPTR     __PRIPTR_PREFIX "o"
00268 # define SCNuPTR     __PRIPTR_PREFIX "u"
00269 # define SCNxPTR     __PRIPTR_PREFIX "x"
00270 
00271 #endif /* C++ && format macros */
00272 
00273 
00274 __BEGIN_DECLS
00275 
00276 #if __WORDSIZE == 64
00277 
00278 /* We have to define the `uintmax_t' type using `ldiv_t'.  */
00279 typedef struct
00280   {
00281     long int quot;          /* Quotient.  */
00282     long int rem;           /* Remainder.  */
00283   } imaxdiv_t;
00284 
00285 #else
00286 
00287 /* We have to define the `uintmax_t' type using `lldiv_t'.  */
00288 typedef struct
00289   {
00290     long long int quot;            /* Quotient.  */
00291     long long int rem;             /* Remainder.  */
00292   } imaxdiv_t;
00293 
00294 #endif
00295 
00296 
00297 /* Compute absolute value of N.  */
00298 extern intmax_t imaxabs (intmax_t __n) __THROW __attribute__ ((__const__));
00299 
00300 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
00301 extern imaxdiv_t imaxdiv (intmax_t __numer, intmax_t __denom)
00302       __THROW __attribute__ ((__const__));
00303 
00304 /* Like `strtol' but convert to `intmax_t'.  */
00305 extern intmax_t strtoimax (__const char *__restrict __nptr,
00306                         char **__restrict __endptr, int __base) __THROW;
00307 
00308 /* Like `strtoul' but convert to `uintmax_t'.  */
00309 extern uintmax_t strtoumax (__const char *__restrict __nptr,
00310                          char ** __restrict __endptr, int __base) __THROW;
00311 
00312 /* Like `wcstol' but convert to `intmax_t'.  */
00313 extern intmax_t wcstoimax (__const __gwchar_t *__restrict __nptr,
00314                         __gwchar_t **__restrict __endptr, int __base)
00315      __THROW;
00316 
00317 /* Like `wcstoul' but convert to `uintmax_t'.  */
00318 extern uintmax_t wcstoumax (__const __gwchar_t *__restrict __nptr,
00319                          __gwchar_t ** __restrict __endptr, int __base)
00320      __THROW;
00321 
00322 #ifdef __USE_EXTERN_INLINES
00323 
00324 # if __WORDSIZE == 64
00325 
00326 extern long int __strtol_internal (__const char *__restrict __nptr,
00327                                char **__restrict __endptr,
00328                                int __base, int __group)
00329   __THROW __nonnull ((1)) __wur;
00330 /* Like `strtol' but convert to `intmax_t'.  */
00331 __extern_inline intmax_t
00332 __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
00333                 int base))
00334 {
00335   return __strtol_internal (nptr, endptr, base, 0);
00336 }
00337 
00338 extern unsigned long int __strtoul_internal (__const char *
00339                                         __restrict __nptr,
00340                                         char ** __restrict __endptr,
00341                                         int __base, int __group)
00342   __THROW __nonnull ((1)) __wur;
00343 /* Like `strtoul' but convert to `uintmax_t'.  */
00344 __extern_inline uintmax_t
00345 __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
00346                 int base))
00347 {
00348   return __strtoul_internal (nptr, endptr, base, 0);
00349 }
00350 
00351 extern long int __wcstol_internal (__const __gwchar_t * __restrict __nptr,
00352                                __gwchar_t **__restrict __endptr,
00353                                int __base, int __group)
00354   __THROW __nonnull ((1)) __wur;
00355 /* Like `wcstol' but convert to `intmax_t'.  */
00356 __extern_inline intmax_t
00357 __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
00358                 __gwchar_t **__restrict endptr, int base))
00359 {
00360   return __wcstol_internal (nptr, endptr, base, 0);
00361 }
00362 
00363 extern unsigned long int __wcstoul_internal (__const __gwchar_t *
00364                                         __restrict __nptr,
00365                                         __gwchar_t **
00366                                         __restrict __endptr,
00367                                         int __base, int __group)
00368   __THROW __nonnull ((1)) __wur;
00369 /* Like `wcstoul' but convert to `uintmax_t'.  */
00370 __extern_inline uintmax_t
00371 __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
00372                 __gwchar_t **__restrict endptr, int base))
00373 {
00374   return __wcstoul_internal (nptr, endptr, base, 0);
00375 }
00376 
00377 # else /* __WORDSIZE == 32 */
00378 
00379 __extension__
00380 extern long long int __strtoll_internal (__const char *__restrict __nptr,
00381                                     char **__restrict __endptr,
00382                                     int __base, int __group)
00383   __THROW __nonnull ((1)) __wur;
00384 /* Like `strtol' but convert to `intmax_t'.  */
00385 __extern_inline intmax_t
00386 __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
00387                 int base))
00388 {
00389   return __strtoll_internal (nptr, endptr, base, 0);
00390 }
00391 
00392 __extension__
00393 extern unsigned long long int __strtoull_internal (__const char *
00394                                              __restrict __nptr,
00395                                              char **
00396                                              __restrict __endptr,
00397                                              int __base,
00398                                              int __group)
00399   __THROW __nonnull ((1)) __wur;
00400 /* Like `strtoul' but convert to `uintmax_t'.  */
00401 __extern_inline uintmax_t
00402 __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
00403                 int base))
00404 {
00405   return __strtoull_internal (nptr, endptr, base, 0);
00406 }
00407 
00408 __extension__
00409 extern long long int __wcstoll_internal (__const __gwchar_t *
00410                                     __restrict __nptr,
00411                                     __gwchar_t **__restrict __endptr,
00412                                     int __base, int __group)
00413   __THROW __nonnull ((1)) __wur;
00414 /* Like `wcstol' but convert to `intmax_t'.  */
00415 __extern_inline intmax_t
00416 __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
00417                 __gwchar_t **__restrict endptr, int base))
00418 {
00419   return __wcstoll_internal (nptr, endptr, base, 0);
00420 }
00421 
00422 
00423 __extension__
00424 extern unsigned long long int __wcstoull_internal (__const __gwchar_t *
00425                                              __restrict __nptr,
00426                                              __gwchar_t **
00427                                              __restrict __endptr,
00428                                              int __base,
00429                                              int __group)
00430   __THROW __nonnull ((1)) __wur;
00431 /* Like `wcstoul' but convert to `uintmax_t'.  */
00432 __extern_inline uintmax_t
00433 __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
00434                 __gwchar_t **__restrict endptr, int base))
00435 {
00436   return __wcstoull_internal (nptr, endptr, base, 0);
00437 }
00438 
00439 # endif       /* __WORDSIZE == 32  */
00440 #endif /* Use extern inlines.  */
00441 
00442 __END_DECLS
00443 
00444 #endif /* inttypes.h */