1 /* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * ISO C 9X: 7.5 Format conversion of integer types <inttypes.h>
27 /* Get the type definitions. */
31 /* The ISO C 9X standard specifies that these macros must only be
32 defined if explicitly requested. */
33 #if !defined __cplusplus || defined __STDC_FORMAT_MACROS
35 /* Macros for printing format specifiers. */
37 /* Decimal notation. */
43 # define PRIdLEAST8 "d"
44 # define PRIdLEAST16 "d"
45 # define PRIdLEAST32 "d"
46 # define PRIdLEAST64 "lld"
48 # define PRIdFAST8 "d"
49 # define PRIdFAST16 "d"
50 # define PRIdFAST32 "d"
51 # define PRIdFAST64 "lld"
59 # define PRIiLEAST8 "i"
60 # define PRIiLEAST16 "i"
61 # define PRIiLEAST32 "i"
62 # define PRIiLEAST64 "lli"
64 # define PRIiFAST8 "i"
65 # define PRIiFAST16 "i"
66 # define PRIiFAST32 "i"
67 # define PRIiFAST64 "lli"
75 # define PRIoLEAST8 "o"
76 # define PRIoLEAST16 "o"
77 # define PRIoLEAST32 "o"
78 # define PRIoLEAST64 "llo"
80 # define PRIoFAST8 "o"
81 # define PRIoFAST16 "o"
82 # define PRIoFAST32 "o"
83 # define PRIoFAST64 "llo"
85 /* Unsigned integers. */
91 # define PRIuLEAST8 "u"
92 # define PRIuLEAST16 "u"
93 # define PRIuLEAST32 "u"
94 # define PRIuLEAST64 "llu"
96 # define PRIuFAST8 "u"
97 # define PRIuFAST16 "u"
98 # define PRIuFAST32 "u"
99 # define PRIuFAST64 "llu"
101 /* lowercase hexadecimal notation. */
105 # define PRIx64 "llx"
107 # define PRIxLEAST8 "x"
108 # define PRIxLEAST16 "x"
109 # define PRIxLEAST32 "x"
110 # define PRIxLEAST64 "llx"
112 # define PRIxFAST8 "x"
113 # define PRIxFAST16 "x"
114 # define PRIxFAST32 "x"
115 # define PRIxFAST64 "llx"
117 /* UPPERCASE hexadecimal notation. */
121 # define PRIX64 "llX"
123 # define PRIXLEAST8 "X"
124 # define PRIXLEAST16 "X"
125 # define PRIXLEAST32 "X"
126 # define PRIXLEAST64 "llX"
128 # define PRIXFAST8 "X"
129 # define PRIXFAST16 "X"
130 # define PRIXFAST32 "X"
131 # define PRIXFAST64 "llX"
134 /* Macros for printing `intmax_t' and `uintmax_t'. */
135 # define PRIdMAX "lld"
136 # define PRIiMAX "lli"
137 # define PRIoMAX "llo"
138 # define PRIuMAX "llu"
139 # define PRIxMAX "llx"
140 # define PRIXMAX "llX"
143 /* Macros for printing `intptr_t' and `uintptr_t'. */
152 /* Macros for scanning format specifiers. */
154 /* Signed decimal notation. */
158 # define SCNd64 "lld"
160 # define SCNdLEAST8 "hhd"
161 # define SCNdLEAST16 "hd"
162 # define SCNdLEAST32 "d"
163 # define SCNdLEAST64 "lld"
165 # define SCNdFAST8 "hhd"
166 # define SCNdFAST16 "d"
167 # define SCNdFAST32 "d"
168 # define SCNdFAST64 "lld"
170 /* Signed decimal notation. */
174 # define SCNi64 "lli"
176 # define SCNiLEAST8 "hhi"
177 # define SCNiLEAST16 "hi"
178 # define SCNiLEAST32 "i"
179 # define SCNiLEAST64 "lli"
181 # define SCNiFAST8 "hhi"
182 # define SCNiFAST16 "i"
183 # define SCNiFAST32 "i"
184 # define SCNiFAST64 "lli"
186 /* Unsigned decimal notation. */
190 # define SCNu64 "llu"
192 # define SCNuLEAST8 "hhu"
193 # define SCNuLEAST16 "hu"
194 # define SCNuLEAST32 "u"
195 # define SCNuLEAST64 "llu"
197 # define SCNuFAST8 "hhu"
198 # define SCNuFAST16 "u"
199 # define SCNuFAST32 "u"
200 # define SCNuFAST64 "llu"
202 /* Octal notation. */
206 # define SCNo64 "llo"
208 # define SCNoLEAST8 "hho"
209 # define SCNoLEAST16 "ho"
210 # define SCNoLEAST32 "o"
211 # define SCNoLEAST64 "llo"
213 # define SCNoFAST8 "hho"
214 # define SCNoFAST16 "o"
215 # define SCNoFAST32 "o"
216 # define SCNoFAST64 "llo"
218 /* Hexadecimal notation. */
222 # define SCNx64 "llx"
224 # define SCNxLEAST8 "hhx"
225 # define SCNxLEAST16 "hx"
226 # define SCNxLEAST32 "x"
227 # define SCNxLEAST64 "llx"
229 # define SCNxFAST8 "hhx"
230 # define SCNxFAST16 "x"
231 # define SCNxFAST32 "x"
232 # define SCNxFAST64 "llx"
235 /* Macros for scanning `intmax_t' and `uintmax_t'. */
236 # define SCNdMAX "lld"
237 # define SCNiMAX "lli"
238 # define SCNoMAX "llo"
239 # define SCNuMAX "llu"
240 # define SCNxMAX "llx"
242 /* Macros for scaning `intptr_t' and `uintptr_t'. */
249 #endif /* C++ && format macros */
254 /* We have to define the `uintmax_t' type using `lldiv_t'. */
256 /* Returned by `lldiv'. */
257 __extension__ typedef struct
259 long long int quot; /* Quotient. */
260 long long int rem; /* Remainder. */
262 # define __lldiv_t_defined 1
265 /* Returned by `imaxdiv'. */
266 typedef lldiv_t imaxdiv_t;
269 /* Compute absolute value of N. */
270 extern intmax_t imaxabs __P ((intmax_t __n)) __attribute__ ((__const__));
272 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
273 extern imaxdiv_t imaxdiv __P ((intmax_t __numer, intmax_t __denom))
274 __attribute__ ((__const__));
276 /* Like `strtol' but convert to `intmax_t'. */
277 extern intmax_t strtoimax __P ((__const char *__restrict __nptr,
278 char **__restrict __endptr, int __base));
280 /* Like `strtoul' but convert to `uintmax_t'. */
281 extern uintmax_t strtoumax __P ((__const char * __restrict __nptr,
282 char ** __restrict __endptr, int __base));
284 /* Like `wcstol' but convert to `intmax_t'. */
285 extern intmax_t wcstoimax __P ((__const wchar_t * __restrict __nptr,
286 wchar_t **__restrict __endptr, int __base));
288 /* Like `wcstoul' but convert to `uintmax_t'. */
289 extern uintmax_t wcstoumax __P ((__const wchar_t * __restrict __nptr,
290 wchar_t ** __restrict __endptr, int __base));
292 #ifdef __USE_EXTERN_INLINES
294 /* We ant to use the appropriate functions from <stdlib.h> but cannot
295 assume the header is read already. */
296 __extension__ extern long long int llabs __P ((long long int __x))
297 __attribute__ ((__const__));
298 __extension__ extern lldiv_t lldiv __P ((long long int __numer,
299 long long int __denom))
300 __attribute__ ((__const__));
303 /* Compute absolute value of N. */
304 extern __inline intmax_t
305 imaxabs (intmax_t __n) __THROW
310 /* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
311 extern __inline imaxdiv_t
312 imaxdiv (intmax_t __numer, intmax_t __denom) __THROW
314 return lldiv (__numer, __denom);
317 /* Like `strtol' but convert to `intmax_t'. */
318 # ifndef __strtoll_internal_defined
320 extern long long int __strtoll_internal __P ((__const char *__restrict __nptr,
321 char **__restrict __endptr,
322 int __base, int __group));
323 # define __strtoll_internal_defined 1
325 extern __inline intmax_t
326 strtoimax (__const char *__restrict nptr, char **__restrict endptr,
329 return __strtoll_internal (nptr, endptr, base, 0);
332 /* Like `strtoul' but convert to `uintmax_t'. */
333 # ifndef __strtoull_internal_defined
335 extern unsigned long long int __strtoull_internal __P ((__const char *
341 # define __strtoull_internal_defined 1
343 extern __inline uintmax_t
344 strtoumax (__const char *__restrict nptr, char **__restrict endptr,
347 return __strtoull_internal (nptr, endptr, base, 0);
350 /* Like `wcstol' but convert to `intmax_t'. */
351 # ifndef __wcstoll_internal_defined
353 extern long long int __wcstoll_internal __P ((__const wchar_t *
355 wchar_t **__restrict __endptr,
356 int __base, int __group));
357 # define __wcstoll_internal_defined 1
359 extern __inline intmax_t
360 wcstoimax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
363 return __wcstoll_internal (nptr, endptr, base, 0);
367 /* Like `wcstoul' but convert to `uintmax_t'. */
368 # ifndef __wcstoull_internal_defined
370 extern unsigned long long int __wcstoull_internal __P ((__const wchar_t *
376 # define __wcstoull_internal_defined 1
378 extern __inline uintmax_t
379 wcstoumax (__const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
382 return __wcstoull_internal (nptr, endptr, base, 0);
384 #endif /* Use extern inlines. */
388 #endif /* inttypes.h */