Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / mfbt / IntegerPrintfMacros.h
blob28bfc1436ed44e0a0c732bf19fd966b171fa5aa2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Implements the C99 <inttypes.h> interface, minus the SCN* format macros. */
9 #ifndef mozilla_IntegerPrintfMacros_h_
10 #define mozilla_IntegerPrintfMacros_h_
13 * MSVC++ doesn't include <inttypes.h>, even in versions shipping <stdint.h>, so
14 * we have to reimplement it there. Note: <inttypes.h> #includes <stdint.h>.
16 * Note that this header DOES NOT implement <inttypes.h>'s scanf macros. MSVC's
17 * scanf doesn't have sufficient format specifier support to implement them
18 * (specifically, to implement scanning into an 8-bit location).
20 * http://stackoverflow.com/questions/3036396/scanfd-char-char-as-int-format-string
22 * Moreover, scanf is a footgun: if the input number exceeds the bounds of the
23 * target type, behavior is undefined (in the compiler sense: that is, this code
24 * could overwrite your hard drive with zeroes):
26 * uint8_t u;
27 * sscanf("256", "%" SCNu8, &u); // BAD
29 * This header will sometimes provide SCN* macros, by dint of being implemented
30 * using <inttypes.h>. But for these reasons, *never* use them!
33 #if defined(MOZ_CUSTOM_INTTYPES_H)
34 # include MOZ_CUSTOM_INTTYPES_H
35 #elif defined(_MSC_VER)
36 # include "mozilla/MSIntTypes.h"
37 #else
38 # include <inttypes.h>
39 #endif
42 * Fix up Android's broken [u]intptr_t inttype macros. Android's PRI*PTR
43 * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t)
44 * is 4 on 32-bit Android. TestTypeTraits.cpp asserts that these new macro
45 * definitions match the actual type sizes seen at compile time.
47 #if defined(ANDROID) && !defined(__LP64__)
48 # undef PRIdPTR /* intptr_t */
49 # define PRIdPTR "d" /* intptr_t */
50 # undef PRIiPTR /* intptr_t */
51 # define PRIiPTR "i" /* intptr_t */
52 # undef PRIoPTR /* uintptr_t */
53 # define PRIoPTR "o" /* uintptr_t */
54 # undef PRIuPTR /* uintptr_t */
55 # define PRIuPTR "u" /* uintptr_t */
56 # undef PRIxPTR /* uintptr_t */
57 # define PRIxPTR "x" /* uintptr_t */
58 # undef PRIXPTR /* uintptr_t */
59 # define PRIXPTR "X" /* uintptr_t */
60 #endif
62 /**
63 * For printing size_t.
65 #define PRIuSIZE PRIuPTR
67 #endif /* mozilla_IntegerPrintfMacros_h_ */