summaryrefslogtreecommitdiffstats
path: root/base/format_macros.h
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 06:53:28 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 06:53:28 +0000
commit34b2b007db875a6acb853c5cd2a247fbb32c0f88 (patch)
tree6dc39bc9f10d6e8eedcdf14821ba9e96b5ccab51 /base/format_macros.h
parent24b857793e27aded8d804a112a5fe6c77e28b081 (diff)
downloadchromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.zip
chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.tar.gz
chromium_src-34b2b007db875a6acb853c5cd2a247fbb32c0f88.tar.bz2
Add compiler-specific "examine printf format" attributes to printfs.
Functions that take a printf-style format get a new annotation, which produces a bunch of compiler warnings when you use printf impoperly. This change adds the annotations and fixes the warnings. We now must use PRId64 for 64-bit numbers and the PRIsz for size_t. Review URL: http://codereview.chromium.org/339059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/format_macros.h')
-rw-r--r--base/format_macros.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/base/format_macros.h b/base/format_macros.h
index 383579f..d218f48 100644
--- a/base/format_macros.h
+++ b/base/format_macros.h
@@ -5,14 +5,21 @@
#ifndef BASE_FORMAT_MACROS_H_
#define BASE_FORMAT_MACROS_H_
-// This file defines the C99 format macros for 64-bit values. If you wish to
-// print a 64-bit value in a portable way do:
+// This file defines the format macros for some integer types.
+
+// To print a 64-bit value in a portable way:
// int64_t value;
// printf("xyz:%" PRId64, value);
+// The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
//
// For wide strings, prepend "Wide" to the macro:
// int64_t value;
// StringPrintf(L"xyz: %" WidePRId64, value);
+//
+// To print a size_t value in a portable way:
+// size_t size;
+// printf("xyz: %" PRIuS, size);
+// The "u" in the macro corresponds to %u, and S is for "size".
#include "build/build_config.h"
@@ -35,6 +42,8 @@
#define WidePRIu64 PRIu64
#define WidePRIx64 PRIx64
+#define PRIuS "zu"
+
#else // OS_WIN
#if !defined(PRId64)
@@ -53,6 +62,8 @@
#define WidePRIu64 L"I64u"
#define WidePRIx64 L"I64x"
+#define PRIuS "Iu"
+
#endif
#endif // !BASE_FORMAT_MACROS_H_