blob: 998f5fe845ed8db0db6170ea6d4fe0884372cec0 [file] [log] [blame]
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +00001/*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_FORMAT_MACROS_H_
12#define RTC_BASE_FORMAT_MACROS_H_
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014// This file defines the format macros for some integer types and is derived
15// from Chromium's base/format_macros.h.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000016
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020017// To print a 64-bit value in a portable way:
18// int64_t value;
19// printf("xyz:%" PRId64, value);
20// The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
21//
22// To print a size_t value in a portable way:
23// size_t size;
Oleh Prypinb1686782019-08-02 09:36:47 +020024// printf("xyz: %" RTC_PRIuS, size);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020025// The "u" in the macro corresponds to %u, and S is for "size".
26
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020027#if defined(WEBRTC_POSIX)
28
29#if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64)
30#error "inttypes.h has already been included before this header file, but "
31#error "without __STDC_FORMAT_MACROS defined."
32#endif
33
34#if !defined(__STDC_FORMAT_MACROS)
35#define __STDC_FORMAT_MACROS
36#endif
37
38#include <inttypes.h>
39
Niels Möllera12c42a2018-07-25 16:05:48 +020040#include "rtc_base/system/arch.h"
41
Oleh Prypinb1686782019-08-02 09:36:47 +020042#define RTC_PRIuS "zu"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020043
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020044#else // WEBRTC_WIN
45
46#include <inttypes.h>
47
Oleh Prypinb1686782019-08-02 09:36:47 +020048// These are being defined without the RTC_ prefix because this is just filling
49// the holes from what's supposed to be already present as part of the C
50// standard, but missing on older MSVC versions.
51
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020052#if !defined(PRId64)
53#define PRId64 "I64d"
54#endif
55
56#if !defined(PRIu64)
57#define PRIu64 "I64u"
58#endif
59
60#if !defined(PRIx64)
61#define PRIx64 "I64x"
62#endif
63
Oleh Prypinb1686782019-08-02 09:36:47 +020064// PRI*64 were added in MSVC 2013, while "%zu" is supported since MSVC 2015
65// (so needs to be special-cased to "%Iu" instead).
66
67#define RTC_PRIuS "Iu"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020068
69#endif
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000070
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020071#endif // RTC_BASE_FORMAT_MACROS_H_