Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: base/format_macros.h

Issue 339059: Add compiler-specific "examine printf format" attributes to printfs. (Closed)
Patch Set: cleanups Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_FORMAT_MACROS_H_ 5 #ifndef BASE_FORMAT_MACROS_H_
6 #define BASE_FORMAT_MACROS_H_ 6 #define BASE_FORMAT_MACROS_H_
7 7
8 // This file defines the C99 format macros for 64-bit values. If you wish to 8 // This file defines the format macros for some integer types.
9 // print a 64-bit value in a portable way do: 9
10 // To print a 64-bit value in a portable way:
10 // int64_t value; 11 // int64_t value;
11 // printf("xyz:%" PRId64, value); 12 // printf("xyz:%" PRId64, value);
13 // The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
12 // 14 //
13 // For wide strings, prepend "Wide" to the macro: 15 // For wide strings, prepend "Wide" to the macro:
14 // int64_t value; 16 // int64_t value;
15 // StringPrintf(L"xyz: %" WidePRId64, value); 17 // StringPrintf(L"xyz: %" WidePRId64, value);
18 //
19 // To print a size_t value in a portable way:
20 // size_t size;
21 // printf("xyz: %" PRIuS, size);
22 // The "u" in the macro corresponds to %u, and S is for "size".
16 23
17 #include "build/build_config.h" 24 #include "build/build_config.h"
18 25
19 #if defined(OS_POSIX) 26 #if defined(OS_POSIX)
20 27
21 #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) 28 #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64)
22 #error "inttypes.h has already been included before this header file, but " 29 #error "inttypes.h has already been included before this header file, but "
23 #error "without __STDC_FORMAT_MACROS defined." 30 #error "without __STDC_FORMAT_MACROS defined."
24 #endif 31 #endif
25 32
26 #if !defined(__STDC_FORMAT_MACROS) 33 #if !defined(__STDC_FORMAT_MACROS)
27 #define __STDC_FORMAT_MACROS 34 #define __STDC_FORMAT_MACROS
28 #endif 35 #endif
29 36
30 #include <inttypes.h> 37 #include <inttypes.h>
31 38
32 // GCC will concatenate wide and narrow strings correctly, so nothing needs to 39 // GCC will concatenate wide and narrow strings correctly, so nothing needs to
33 // be done here. 40 // be done here.
34 #define WidePRId64 PRId64 41 #define WidePRId64 PRId64
35 #define WidePRIu64 PRIu64 42 #define WidePRIu64 PRIu64
36 #define WidePRIx64 PRIx64 43 #define WidePRIx64 PRIx64
37 44
45 #define PRIuS "zu"
46
38 #else // OS_WIN 47 #else // OS_WIN
39 48
40 #if !defined(PRId64) 49 #if !defined(PRId64)
41 #define PRId64 "I64d" 50 #define PRId64 "I64d"
42 #endif 51 #endif
43 52
44 #if !defined(PRIu64) 53 #if !defined(PRIu64)
45 #define PRIu64 "I64u" 54 #define PRIu64 "I64u"
46 #endif 55 #endif
47 56
48 #if !defined(PRIx64) 57 #if !defined(PRIx64)
49 #define PRIx64 "I64x" 58 #define PRIx64 "I64x"
50 #endif 59 #endif
51 60
52 #define WidePRId64 L"I64d" 61 #define WidePRId64 L"I64d"
53 #define WidePRIu64 L"I64u" 62 #define WidePRIu64 L"I64u"
54 #define WidePRIx64 L"I64x" 63 #define WidePRIx64 L"I64x"
55 64
65 #define PRIuS "Iu"
66
56 #endif 67 #endif
57 68
58 #endif // !BASE_FORMAT_MACROS_H_ 69 #endif // !BASE_FORMAT_MACROS_H_
OLDNEW
« no previous file with comments | « base/compiler_specific.h ('k') | base/histogram.cc » ('j') | base/string_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698