1 // Copyright 2009 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_FORMAT_MACROS_H_
6 #define BASE_FORMAT_MACROS_H_
8 // This file defines the format macros for some integer types.
10 // To print a 64-bit value in a portable way:
12 // printf("xyz:%" PRId64, value);
13 // The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
15 // For wide strings, prepend "Wide" to the macro:
17 // StringPrintf(L"xyz: %" WidePRId64, value);
19 // To print a size_t value in a portable way:
21 // printf("xyz: %" PRIuS, size);
22 // The "u" in the macro corresponds to %u, and S is for "size".
27 #include "build/build_config.h"
29 #if (BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)) && \
30 (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64)
31 #error "inttypes.h has already been included before this header file, but "
32 #error "without __STDC_FORMAT_MACROS defined."
35 #if (BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)) && \
36 !defined(__STDC_FORMAT_MACROS)
37 #define __STDC_FORMAT_MACROS
44 #if !defined(PRId64) || !defined(PRIu64) || !defined(PRIx64)
45 #error "inttypes.h provided by win toolchain should define these."
48 #define WidePRId64 L"I64d"
49 #define WidePRIu64 L"I64u"
50 #define WidePRIx64 L"I64x"
56 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
58 // GCC will concatenate wide and narrow strings correctly, so nothing needs to
60 #define WidePRId64 PRId64
61 #define WidePRIu64 PRIu64
62 #define WidePRIx64 PRIx64
68 #endif // BUILDFLAG(IS_WIN)
70 // The size of NSInteger and NSUInteger varies between 32-bit and 64-bit
71 // architectures and Apple does not provides standard format macros and
72 // recommends casting. This has many drawbacks, so instead define macros
73 // for formatting those types.
74 #if BUILDFLAG(IS_APPLE)
75 #if defined(ARCH_CPU_64_BITS)
85 #else // defined(ARCH_CPU_64_BITS)
96 #endif // BUILDFLAG(IS_APPLE)
98 #endif // BASE_FORMAT_MACROS_H_