msvc_inttypes.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // ISO C9x compliant inttypes.h for Microsoft Visual Studio
  2. // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
  3. //
  4. // Copyright (c) 2006 Alexander Chemeris
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // 1. Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. //
  12. // 2. Redistributions in binary form must reproduce the above copyright
  13. // notice, this list of conditions and the following disclaimer in the
  14. // documentation and/or other materials provided with the distribution.
  15. //
  16. // 3. The name of the author may be used to endorse or promote products
  17. // derived from this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  20. // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  27. // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  28. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. #ifndef _MSC_VER // [
  32. #error "Use this header only with Microsoft Visual C++ compilers!"
  33. #endif // _MSC_VER ]
  34. #ifndef _MSC_INTTYPES_H_ // [
  35. #define _MSC_INTTYPES_H_
  36. #if _MSC_VER > 1000
  37. #pragma once
  38. #endif
  39. #include "msvc_stdint.h"
  40. // 7.8 Format conversion of integer types
  41. typedef struct {
  42. intmax_t quot;
  43. intmax_t rem;
  44. } imaxdiv_t;
  45. // 7.8.1 Macros for format specifiers
  46. #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
  47. // The fprintf macros for signed integers are:
  48. #define PRId8 "d"
  49. #define PRIi8 "i"
  50. #define PRIdLEAST8 "d"
  51. #define PRIiLEAST8 "i"
  52. #define PRIdFAST8 "d"
  53. #define PRIiFAST8 "i"
  54. #define PRId16 "hd"
  55. #define PRIi16 "hi"
  56. #define PRIdLEAST16 "hd"
  57. #define PRIiLEAST16 "hi"
  58. #define PRIdFAST16 "hd"
  59. #define PRIiFAST16 "hi"
  60. #define PRId32 "I32d"
  61. #define PRIi32 "I32i"
  62. #define PRIdLEAST32 "I32d"
  63. #define PRIiLEAST32 "I32i"
  64. #define PRIdFAST32 "I32d"
  65. #define PRIiFAST32 "I32i"
  66. #define PRId64 "I64d"
  67. #define PRIi64 "I64i"
  68. #define PRIdLEAST64 "I64d"
  69. #define PRIiLEAST64 "I64i"
  70. #define PRIdFAST64 "I64d"
  71. #define PRIiFAST64 "I64i"
  72. #define PRIdMAX "I64d"
  73. #define PRIiMAX "I64i"
  74. #define PRIdPTR "Id"
  75. #define PRIiPTR "Ii"
  76. // The fprintf macros for unsigned integers are:
  77. #define PRIo8 "o"
  78. #define PRIu8 "u"
  79. #define PRIx8 "x"
  80. #define PRIX8 "X"
  81. #define PRIoLEAST8 "o"
  82. #define PRIuLEAST8 "u"
  83. #define PRIxLEAST8 "x"
  84. #define PRIXLEAST8 "X"
  85. #define PRIoFAST8 "o"
  86. #define PRIuFAST8 "u"
  87. #define PRIxFAST8 "x"
  88. #define PRIXFAST8 "X"
  89. #define PRIo16 "ho"
  90. #define PRIu16 "hu"
  91. #define PRIx16 "hx"
  92. #define PRIX16 "hX"
  93. #define PRIoLEAST16 "ho"
  94. #define PRIuLEAST16 "hu"
  95. #define PRIxLEAST16 "hx"
  96. #define PRIXLEAST16 "hX"
  97. #define PRIoFAST16 "ho"
  98. #define PRIuFAST16 "hu"
  99. #define PRIxFAST16 "hx"
  100. #define PRIXFAST16 "hX"
  101. #define PRIo32 "I32o"
  102. #define PRIu32 "I32u"
  103. #define PRIx32 "I32x"
  104. #define PRIX32 "I32X"
  105. #define PRIoLEAST32 "I32o"
  106. #define PRIuLEAST32 "I32u"
  107. #define PRIxLEAST32 "I32x"
  108. #define PRIXLEAST32 "I32X"
  109. #define PRIoFAST32 "I32o"
  110. #define PRIuFAST32 "I32u"
  111. #define PRIxFAST32 "I32x"
  112. #define PRIXFAST32 "I32X"
  113. #define PRIo64 "I64o"
  114. #define PRIu64 "I64u"
  115. #define PRIx64 "I64x"
  116. #define PRIX64 "I64X"
  117. #define PRIoLEAST64 "I64o"
  118. #define PRIuLEAST64 "I64u"
  119. #define PRIxLEAST64 "I64x"
  120. #define PRIXLEAST64 "I64X"
  121. #define PRIoFAST64 "I64o"
  122. #define PRIuFAST64 "I64u"
  123. #define PRIxFAST64 "I64x"
  124. #define PRIXFAST64 "I64X"
  125. #define PRIoMAX "I64o"
  126. #define PRIuMAX "I64u"
  127. #define PRIxMAX "I64x"
  128. #define PRIXMAX "I64X"
  129. #define PRIoPTR "Io"
  130. #define PRIuPTR "Iu"
  131. #define PRIxPTR "Ix"
  132. #define PRIXPTR "IX"
  133. // The fscanf macros for signed integers are:
  134. #define SCNd8 "d"
  135. #define SCNi8 "i"
  136. #define SCNdLEAST8 "d"
  137. #define SCNiLEAST8 "i"
  138. #define SCNdFAST8 "d"
  139. #define SCNiFAST8 "i"
  140. #define SCNd16 "hd"
  141. #define SCNi16 "hi"
  142. #define SCNdLEAST16 "hd"
  143. #define SCNiLEAST16 "hi"
  144. #define SCNdFAST16 "hd"
  145. #define SCNiFAST16 "hi"
  146. #define SCNd32 "ld"
  147. #define SCNi32 "li"
  148. #define SCNdLEAST32 "ld"
  149. #define SCNiLEAST32 "li"
  150. #define SCNdFAST32 "ld"
  151. #define SCNiFAST32 "li"
  152. #define SCNd64 "I64d"
  153. #define SCNi64 "I64i"
  154. #define SCNdLEAST64 "I64d"
  155. #define SCNiLEAST64 "I64i"
  156. #define SCNdFAST64 "I64d"
  157. #define SCNiFAST64 "I64i"
  158. #define SCNdMAX "I64d"
  159. #define SCNiMAX "I64i"
  160. #ifdef _WIN64 // [
  161. # define SCNdPTR "I64d"
  162. # define SCNiPTR "I64i"
  163. #else // _WIN64 ][
  164. # define SCNdPTR "ld"
  165. # define SCNiPTR "li"
  166. #endif // _WIN64 ]
  167. // The fscanf macros for unsigned integers are:
  168. #define SCNo8 "o"
  169. #define SCNu8 "u"
  170. #define SCNx8 "x"
  171. #define SCNX8 "X"
  172. #define SCNoLEAST8 "o"
  173. #define SCNuLEAST8 "u"
  174. #define SCNxLEAST8 "x"
  175. #define SCNXLEAST8 "X"
  176. #define SCNoFAST8 "o"
  177. #define SCNuFAST8 "u"
  178. #define SCNxFAST8 "x"
  179. #define SCNXFAST8 "X"
  180. #define SCNo16 "ho"
  181. #define SCNu16 "hu"
  182. #define SCNx16 "hx"
  183. #define SCNX16 "hX"
  184. #define SCNoLEAST16 "ho"
  185. #define SCNuLEAST16 "hu"
  186. #define SCNxLEAST16 "hx"
  187. #define SCNXLEAST16 "hX"
  188. #define SCNoFAST16 "ho"
  189. #define SCNuFAST16 "hu"
  190. #define SCNxFAST16 "hx"
  191. #define SCNXFAST16 "hX"
  192. #define SCNo32 "lo"
  193. #define SCNu32 "lu"
  194. #define SCNx32 "lx"
  195. #define SCNX32 "lX"
  196. #define SCNoLEAST32 "lo"
  197. #define SCNuLEAST32 "lu"
  198. #define SCNxLEAST32 "lx"
  199. #define SCNXLEAST32 "lX"
  200. #define SCNoFAST32 "lo"
  201. #define SCNuFAST32 "lu"
  202. #define SCNxFAST32 "lx"
  203. #define SCNXFAST32 "lX"
  204. #define SCNo64 "I64o"
  205. #define SCNu64 "I64u"
  206. #define SCNx64 "I64x"
  207. #define SCNX64 "I64X"
  208. #define SCNoLEAST64 "I64o"
  209. #define SCNuLEAST64 "I64u"
  210. #define SCNxLEAST64 "I64x"
  211. #define SCNXLEAST64 "I64X"
  212. #define SCNoFAST64 "I64o"
  213. #define SCNuFAST64 "I64u"
  214. #define SCNxFAST64 "I64x"
  215. #define SCNXFAST64 "I64X"
  216. #define SCNoMAX "I64o"
  217. #define SCNuMAX "I64u"
  218. #define SCNxMAX "I64x"
  219. #define SCNXMAX "I64X"
  220. #ifdef _WIN64 // [
  221. # define SCNoPTR "I64o"
  222. # define SCNuPTR "I64u"
  223. # define SCNxPTR "I64x"
  224. # define SCNXPTR "I64X"
  225. #else // _WIN64 ][
  226. # define SCNoPTR "lo"
  227. # define SCNuPTR "lu"
  228. # define SCNxPTR "lx"
  229. # define SCNXPTR "lX"
  230. #endif // _WIN64 ]
  231. #endif // __STDC_FORMAT_MACROS ]
  232. // 7.8.2 Functions for greatest-width integer types
  233. // 7.8.2.1 The imaxabs function
  234. #define imaxabs _abs64
  235. // 7.8.2.2 The imaxdiv function
  236. // This is modified version of div() function from Microsoft's div.c found
  237. // in %MSVC.NET%\crt\src\div.c
  238. #ifdef STATIC_IMAXDIV // [
  239. static
  240. #else // STATIC_IMAXDIV ][
  241. _inline
  242. #endif // STATIC_IMAXDIV ]
  243. imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
  244. {
  245. imaxdiv_t result;
  246. result.quot = numer / denom;
  247. result.rem = numer % denom;
  248. if (numer < 0 && result.rem > 0) {
  249. // did division wrong; must fix up
  250. ++result.quot;
  251. result.rem -= denom;
  252. }
  253. return result;
  254. }
  255. // 7.8.2.3 The strtoimax and strtoumax functions
  256. #define strtoimax _strtoi64
  257. #define strtoumax _strtoui64
  258. // 7.8.2.4 The wcstoimax and wcstoumax functions
  259. #define wcstoimax _wcstoi64
  260. #define wcstoumax _wcstoui64
  261. #endif // _MSC_INTTYPES_H_ ]