michael@0: // Copyright (c) 2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_FORMAT_MACROS_H_ michael@0: #define BASE_FORMAT_MACROS_H_ michael@0: michael@0: // This file defines the format macros for some integer types. michael@0: michael@0: // To print a 64-bit value in a portable way: michael@0: // int64_t value; michael@0: // printf("xyz:%" PRId64, value); michael@0: // The "d" in the macro corresponds to %d; you can also use PRIu64 etc. michael@0: // michael@0: // For wide strings, prepend "Wide" to the macro: michael@0: // int64_t value; michael@0: // StringPrintf(L"xyz: %" WidePRId64, value); michael@0: // michael@0: // To print a size_t value in a portable way: michael@0: // size_t size; michael@0: // printf("xyz: %" PRIuS, size); michael@0: // The "u" in the macro corresponds to %u, and S is for "size". michael@0: michael@0: #include "build/build_config.h" michael@0: michael@0: #if defined(OS_POSIX) michael@0: michael@0: #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) michael@0: #error "inttypes.h has already been included before this header file, but " michael@0: #error "without __STDC_FORMAT_MACROS defined." michael@0: #endif michael@0: michael@0: #if !defined(__STDC_FORMAT_MACROS) michael@0: #define __STDC_FORMAT_MACROS michael@0: #endif michael@0: michael@0: #include michael@0: michael@0: // GCC will concatenate wide and narrow strings correctly, so nothing needs to michael@0: // be done here. michael@0: #define WidePRId64 PRId64 michael@0: #define WidePRIu64 PRIu64 michael@0: #define WidePRIx64 PRIx64 michael@0: michael@0: #if !defined(PRIuS) michael@0: #define PRIuS "zu" michael@0: #endif michael@0: michael@0: #else // OS_WIN michael@0: michael@0: #if !defined(PRId64) michael@0: #define PRId64 "I64d" michael@0: #endif michael@0: michael@0: #if !defined(PRIu64) michael@0: #define PRIu64 "I64u" michael@0: #endif michael@0: michael@0: #if !defined(PRIx64) michael@0: #define PRIx64 "I64x" michael@0: #endif michael@0: michael@0: #define WidePRId64 L"I64d" michael@0: #define WidePRIu64 L"I64u" michael@0: #define WidePRIx64 L"I64x" michael@0: michael@0: #if !defined(PRIuS) michael@0: #define PRIuS "Iu" michael@0: #endif michael@0: michael@0: #endif michael@0: michael@0: #endif // BASE_FORMAT_MACROS_H_