format_macros.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  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. #ifndef RTC_BASE_FORMAT_MACROS_H_
  11. #define RTC_BASE_FORMAT_MACROS_H_
  12. // This file defines the format macros for some integer types and is derived
  13. // from Chromium's base/format_macros.h.
  14. // To print a 64-bit value in a portable way:
  15. // int64_t value;
  16. // printf("xyz:%" PRId64, value);
  17. // The "d" in the macro corresponds to %d; you can also use PRIu64 etc.
  18. //
  19. // To print a size_t value in a portable way:
  20. // size_t size;
  21. // printf("xyz: %" RTC_PRIuS, size);
  22. // The "u" in the macro corresponds to %u, and S is for "size".
  23. #if defined(WEBRTC_POSIX)
  24. #if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64)
  25. #error "inttypes.h has already been included before this header file, but "
  26. #error "without __STDC_FORMAT_MACROS defined."
  27. #endif
  28. #if !defined(__STDC_FORMAT_MACROS)
  29. #define __STDC_FORMAT_MACROS
  30. #endif
  31. #include <inttypes.h>
  32. #include "rtc_base/system/arch.h"
  33. #define RTC_PRIuS "zu"
  34. #else // WEBRTC_WIN
  35. #include <inttypes.h>
  36. #if !defined(PRId64) || !defined(PRIu64) || !defined(PRIx64)
  37. #error "inttypes.h provided by win toolchain should define these."
  38. #endif
  39. // PRI*64 were added in MSVC 2013, while "%zu" is supported since MSVC 2015
  40. // (so needs to be special-cased to "%Iu" instead).
  41. #define RTC_PRIuS "Iu"
  42. #endif
  43. #endif // RTC_BASE_FORMAT_MACROS_H_