summaryrefslogtreecommitdiffstats
path: root/base/format_macros.h
diff options
context:
space:
mode:
authorsdefresne@chromium.org <sdefresne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-10 20:16:34 +0000
committersdefresne@chromium.org <sdefresne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-10 20:16:34 +0000
commit3394a7c1d759a4786315a442532f79c7dfe55c4e (patch)
tree543d5099d59020d9d5837c459ae1d3a1da5f9fc5 /base/format_macros.h
parent4ef5e13162cbfb214d9819ee2067388d6877cb5f (diff)
downloadchromium_src-3394a7c1d759a4786315a442532f79c7dfe55c4e.zip
chromium_src-3394a7c1d759a4786315a442532f79c7dfe55c4e.tar.gz
chromium_src-3394a7c1d759a4786315a442532f79c7dfe55c4e.tar.bz2
Define print format macros for NSInteger & NSUInteger
The size of NSInteger and NSUInteger varies between 32-bit and 64-bit architectures, however does not provides macro to safely format them and instead recommend casting the value to the larger version that is used on 64-bit architecture. Using a cast could cause some formatting to be missed (if the type of a variable changes), so instead we define our own macros to format those types safely. BUG=349458 Review URL: https://codereview.chromium.org/192443003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/format_macros.h')
-rw-r--r--base/format_macros.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/base/format_macros.h b/base/format_macros.h
index 466d79b..4d90c59 100644
--- a/base/format_macros.h
+++ b/base/format_macros.h
@@ -46,6 +46,34 @@
#define PRIuS "zu"
#endif
+// The size of NSInteger and NSUInteger varies between 32-bit and 64-bit
+// architectures and Apple does not provides standard format macros and
+// recommends casting. This has many drawbacks, so instead define macros
+// for formatting those types.
+#if defined(OS_MACOSX)
+#if defined(ARCH_CPU_64_BITS)
+#if !defined(PRIdNS)
+#define PRIdNS "ld"
+#endif
+#if !defined(PRIuNS)
+#define PRIuNS "lu"
+#endif
+#if !defined(PRIxNS)
+#define PRIxNS "lx"
+#endif
+#else // defined(ARCH_CPU_64_BITS)
+#if !defined(PRIdNS)
+#define PRIdNS "d"
+#endif
+#if !defined(PRIuNS)
+#define PRIuNS "u"
+#endif
+#if !defined(PRIxNS)
+#define PRIxNS "x"
+#endif
+#endif
+#endif // defined(OS_MACOSX)
+
#else // OS_WIN
#if !defined(PRId64)