home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / inttypes.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  16.9 KB  |  473 lines

  1. #ifdef __cplusplus
  2.    extern "C" {
  3. #endif
  4.    /********************************************************************/
  5.    /*  <inttypes.h> header file                                        */
  6.    /*                                                                  */
  7.    /*  VisualAge for C++ for Windows, Version 3.5                      */
  8.    /*    Licensed Material - Property of IBM                           */
  9.    /*                                                                  */
  10.    /*  5801-ARR and Other Materials                                    */
  11.    /*                                                                  */
  12.    /*  (c) Copyright IBM Corp 1995, 1996. All rights reserved.         */
  13.    /*                                                                  */
  14.    /********************************************************************/
  15.  
  16. /*********************** Basic integer types *****************************
  17. **
  18. ** The following defines the basic fixed-size integer types.
  19. **
  20. ** intmax_t and uintmax_t are the largest signed and unsigned integer
  21. ** types supported by the implementation.
  22. **
  23. ** intptr_t and uintptr_t are signed and unsigned integer types large enough
  24. ** to hold a pointer; that is, pointers can be assigned into or from
  25. ** these integer types without losing precision.
  26. **
  27. ** intfast_t and uintfast_t are the most efficient signed and unsigned
  28. ** integer types of the implementation.
  29. **
  30. */
  31.  
  32. typedef signed char int8_t;         /* 8-bit signed integer */
  33. typedef signed short int16_t;       /* 16-bit signed integer */
  34. typedef signed int int32_t;         /* 32-bit signed integer */
  35. typedef unsigned char uint8_t;      /* 8-bit unsigned integer */
  36. typedef unsigned short uint16_t;    /* 16-bit unsigned integer */
  37. typedef unsigned int uint32_t;      /* 32-bit unsigned integer */
  38. #if _LONG_LONG
  39. typedef __int64 int64_t;            /* 64-bit signed integer */
  40. typedef unsigned __int64 uint64_t;  /* 64-bit unsigned integer */
  41. typedef signed long long intmax_t;       /* largest signed integer supported */
  42. typedef unsigned long long uintmax_t;    /* largest unsigned integer supported */
  43. #else
  44. typedef signed long intmax_t;       /* largest signed integer supported */
  45. typedef unsigned long uintmax_t;    /* largest unsigned integer supported */
  46. #endif
  47. typedef signed int intptr_t;        /* signed integer type capable of holding a void * */
  48. typedef unsigned int uintptr_t;     /* unsigned integer type capable of holding a void * */
  49. typedef signed int intfast_t;       /* most efficient signed integer type */
  50. typedef unsigned int uintfast_t;    /* most efficient unsigned integer type */
  51.  
  52.  
  53. /*********************** Extended integer types *************************
  54. **
  55. ** The following defines smallest integer types that can hold n bits.
  56. **
  57. */
  58.  
  59. typedef signed char int_least8_t;   /* smallest signed integer of at least 8 bits */
  60. typedef int int_fast8_t;            /* the most efficient integer of at least 8 bits */
  61. typedef signed short int_least16_t; /* smallest signed integer of at least 16 bits */
  62. typedef int int_fast16_t;           /* the most efficient integer of at least 16 bits */
  63. typedef signed int int_least32_t;   /* smallest signed integer of at least 32 bits */
  64. typedef int int_fast32_t;           /* the most efficient integer of at least 32 bits */
  65. #ifdef _LONG_LONG
  66. typedef __int64 int_least64_t;      /* smallest signed integer of at least 64 bits */
  67. typedef __int64 int_fast64_t;       /* the most efficient integer of at least 64 bits */
  68. #endif
  69. typedef unsigned char uint_least8_t;   /* smallest unsigned integer of at least 8 bits */
  70. typedef unsigned int uint_fast8_t;     /* the most efficient unsigned integer of at least 8 bits */
  71. typedef unsigned short uint_least16_t; /* smallest unsigned integer of at least 16 bits */
  72. typedef unsigned int uint_fast16_t;    /* the most efficient unsigned integer of at least 16 bits */
  73. typedef unsigned int uint_least32_t;   /* smallest unsigned integer of at least 32 bits */
  74. typedef unsigned int uint_fast32_t;    /* the most efficient unsigned integer of at least 32 bits */
  75. #ifdef _LONG_LONG
  76. typedef unsigned __int64 uint_least64_t; /* smallest unsigned integer of at least 64 bits */
  77. typedef unsigned __int64 uint_fast64_t;  /* the most efficient unsigned integer of at least 64 bits */
  78. #endif
  79.  
  80.  
  81. /* ************************** limits ***********************************
  82. **
  83. ** The following defines the limits for the above types.
  84. **
  85. ** NOTE : A programmer can test to see whether an implementation supports
  86. ** a particular size of integer by testing if the macro that gives the
  87. ** maximum for that datatype is defined. For example, if #ifdef UINT64_MAX
  88. ** tests false, the implementation does not support unsigned 64 bit integers.
  89. **
  90. */
  91.  
  92. #define INT8_MIN                    (-128)
  93. #define INT16_MIN                   (-32767-1)
  94. #define INT32_MIN                   (-2147483647-1)
  95. #if _LONG_LONG
  96. #define INT64_MIN                   (-9223372036854775807LL-1LL)
  97. #endif
  98. #define INT_LEAST8_MIN              (-128)
  99. #define INT_LEAST16_MIN             (-32767-1)
  100. #define INT_LEAST32_MIN             (-2147483647-1)
  101. #if _LONG_LONG
  102. #define INT_LEAST64_MIN             (-9223372036854775807LL-1LL)
  103. #endif
  104. #define INT_FAST8_MIN               (-128)
  105. #define INT_FAST16_MIN              (-32767-1)
  106. #define INT_FAST32_MIN              (-2147483647-1)
  107. #if _LONG_LONG
  108. #define INT_FAST64_MIN              (-9223372036854775807LL-1LL)
  109. #endif
  110. #define INT8_MAX                    (127)
  111. #define INT16_MAX                   (32767)
  112. #define INT32_MAX                   (2147483647)
  113. #if _LONG_LONG
  114. #define INT64_MAX                   (9223372036854775807LL)
  115. #endif
  116. #define UINT8_MAX                   (255U)
  117. #define UINT16_MAX                  (65535U)
  118. #define UINT32_MAX                  (4294967295U)
  119. #if _LONG_LONG
  120. #define UINT64_MAX                  (18446744073709551615ULL)
  121. #endif
  122.  
  123. #if _LONG_LONG
  124. #define INTMAX_MIN                  (-9223372036854775807LL-1LL)
  125. #define INTMAX_MAX                  (9223372036854775807LL)
  126. #define UINTMAX_MAX                 (18446744073709551615ULL)
  127. #else
  128. #define INTMAX_MIN                  (-2147483647L-1)
  129. #define INTMAX_MAX                  (2147483647L)
  130. #define UINTMAX_MAX                 (4294967295UL)
  131. #endif
  132. #define INTFAST_MIN                 (-2147483647L-1)
  133. #define INTFAST_MAX                 (2147483647L)
  134. #define UINTFAST_MAX                (4294967295U)
  135. #define INT_LEAST8_MAX              (127)
  136. #define INT_LEAST16_MAX             (32767)
  137. #define INT_LEAST32_MAX             (2147483647)
  138. #if _LONG_LONG
  139. #define INT_LEAST64_MAX             (9223372036854775807LL)
  140. #endif
  141. #define INT_FAST8_MAX               (2147483647)
  142. #define INT_FAST16_MAX              (2147483647)
  143. #define INT_FAST32_MAX              (2147483647)
  144. #if _LONG_LONG
  145. #define INT_FAST64_MAX              (9223372036854775807LL)
  146. #endif
  147. #define UINT_LEAST8_MAX             (255U)
  148. #define UINT_LEAST16_MAX            (65535U)
  149. #define UINT_LEAST32_MAX            (4294967295U)
  150. #if _LONG_LONG
  151. #define UINT_LEAST64_MAX            (18446744073709551615ULL)
  152. #endif
  153. #define UINT_FAST8_MAX              (4294967295U)
  154. #define UINT_FAST16_MAX             (4294967295U)
  155. #define UINT_FAST32_MAX             (4294967295U)
  156. #if _LONG_LONG
  157. #define UINT_FAST64_MAX             (18446744073709551615ULL)
  158. #endif
  159.  
  160. /* The following 2 macros are provided for testing whether the types
  161. ** intptr_t and uintptr_t (integers large enough to hold a void *) are
  162. ** defined in this header. They are needed in case the architecture can't
  163. ** represent a pointer in any standard integral type.
  164. */
  165.  
  166. #define INTPTR_MAX                  (2147483647)
  167. #define UINTPTR_MAX                 (4294967295U)
  168.  
  169.  
  170. /* ************************ CONSTANTS ********************************
  171. **
  172. ** The following macros create constants of the above types. The intent is
  173. ** that:
  174. **   Constants defined using these macros have a specific length and
  175. **     signedness.
  176. */
  177.  
  178. #define __CONCAT__(A,B)             A ## B
  179. #define INT8_C(c)                   (c)
  180. #define UINT8_C(c)                  __CONCAT__(c,u)
  181. #define INT16_C(c)                  (c)
  182. #define UINT16_C(c)                 __CONCAT__(c,u)
  183. #define INT32_C(c)                  (c)
  184. #define UINT32_C(c)                 __CONCAT__(c,u)
  185. #define INT64_C(c)                  __CONCAT__(c,ll)
  186. #define UINT64_C(c)                 __CONCAT__(c,ull)
  187. #define INTMAX_C(c)                 __CONCAT__(c,ll)
  188. #define UINTMAX_C(c)                __CONCAT__(c,ull)
  189.  
  190.  
  191. /************************* FORMATTED I/O ********************************
  192. **
  193. ** The following macros can be used even when an implementation has not
  194. ** extended the printf/scanf family of functions.
  195. **
  196. ** The form of the names of the macros is either "PRI" for printf specifiers
  197. ** or "SCN" for scanf specifiers followed by the conversion specifier letter
  198. ** followed by the datatype size. For example, PRId32 is the macro for
  199. ** the printf d conversion specifier with the flags for 32 bit datatype.
  200. **
  201. ** Separate printf versus scanf macros are given because typically different
  202. ** size flags must prefix the conversion specifier letter.
  203. **
  204. *** An example using one of these macros:
  205. **
  206. **    uint64_t u;
  207. **    printf("u = %016" PRIx64 "\n", u);
  208. **
  209. */
  210.  
  211. /* For signed integers */
  212. #define PRId8                       "d"
  213. #define PRId16                      "d"
  214. #define PRId32                      "d"
  215. #if _LONG_LONG
  216. #define PRId64                    "lld"
  217. #endif
  218. #define PRIdFAST8                   "d"
  219. #define PRIdFAST16                  "d"
  220. #define PRIdFAST32                  "d"
  221. #if _LONG_LONG
  222. #define PRIdFAST64                "lld"
  223. #endif
  224. #define PRIdLEAST8                  "d"
  225. #define PRIdLEAST16                 "d"
  226. #define PRIdLEAST32                 "d"
  227. #if _LONG_LONG
  228. #define PRIdLEAST64               "lld"
  229. #endif
  230. #define PRIi8                       "i"
  231. #define PRIi16                      "i"
  232. #define PRIi32                      "i"
  233. #if _LONG_LONG
  234. #define PRIi64                    "lli"
  235. #endif
  236. #define PRIiFAST8                   "i"
  237. #define PRIiFAST16                  "i"
  238. #define PRIiFAST32                  "i"
  239. #if _LONG_LONG
  240. #define PRIiFAST64                "lli"
  241. #endif
  242. #define PRIiLEAST8                  "i"
  243. #define PRIiLEAST16                 "i"
  244. #define PRIiLEAST32                 "i"
  245. #if _LONG_LONG
  246. #define PRIiLEAST64               "lli"
  247. #endif
  248. #define PRIo8                       "o"
  249. #define PRIo16                      "o"
  250. #define PRIo32                      "o"
  251. #if _LONG_LONG
  252. #define PRIo64                    "llo"
  253. #endif
  254. #define PRIoFAST8                   "o"
  255. #define PRIoFAST16                  "o"
  256. #define PRIoFAST32                  "o"
  257. #if _LONG_LONG
  258. #define PRIoFAST64                "llo"
  259. #endif
  260. #define PRIoLEAST8                  "o"
  261. #define PRIoLEAST16                 "o"
  262. #define PRIoLEAST32                 "o"
  263. #if _LONG_LONG
  264. #define PRIoLEAST64               "llo"
  265. #endif
  266. #define PRIx8                       "x"
  267. #define PRIx16                      "x"
  268. #define PRIx32                      "x"
  269. #if _LONG_LONG
  270. #define PRIx64                    "llx"
  271. #endif
  272. #define PRIxFAST8                   "x"
  273. #define PRIxFAST16                  "x"
  274. #define PRIxFAST32                  "x"
  275. #if _LONG_LONG
  276. #define PRIxFAST64                "llx"
  277. #endif
  278. #define PRIxLEAST8                  "x"
  279. #define PRIxLEAST16                 "x"
  280. #define PRIxLEAST32                 "x"
  281. #if _LONG_LONG
  282. #define PRIxLEAST64               "llx"
  283. #endif
  284. #define PRIX8                       "X"
  285. #define PRIX16                      "X"
  286. #define PRIX32                      "X"
  287. #if _LONG_LONG
  288. #define PRIX64                    "llX"
  289. #endif
  290. #define PRIXFAST8                   "X"
  291. #define PRIXFAST16                  "X"
  292. #define PRIXFAST32                  "X"
  293. #if _LONG_LONG
  294. #define PRIXFAST64                "llX"
  295. #endif
  296. #define PRIXLEAST8                  "X"
  297. #define PRIXLEAST16                 "X"
  298. #define PRIXLEAST32                 "X"
  299. #if _LONG_LONG
  300. #define PRIXLEAST64               "llX"
  301. #endif
  302.  
  303. /* For unsigned integers */
  304. #define PRIu8                       "u"
  305. #define PRIu16                      "u"
  306. #define PRIu32                      "u"
  307. #if _LONG_LONG
  308. #define PRIu64                    "llu"
  309. #endif
  310. #define PRIuFAST8                   "u"
  311. #define PRIuFAST16                  "u"
  312. #define PRIuFAST32                  "u"
  313. #if _LONG_LONG
  314. #define PRIuFAST64                "llu"
  315. #endif
  316. #define PRIuLEAST8                  "u"
  317. #define PRIuLEAST16                 "u"
  318. #define PRIuLEAST32                 "u"
  319. #if _LONG_LONG
  320. #define PRIuLEAST64               "llu"
  321. #endif
  322.  
  323. /* scanf macros */
  324. #define SCNd16                     "hd"
  325. #define SCNd32                      "d"
  326. #if _LONG_LONG
  327. #define SCNd64                    "lld"
  328. #endif
  329. #define SCNi16                     "hi"
  330. #define SCNi32                      "i"
  331. #if _LONG_LONG
  332. #define SCNi64                    "lli"
  333. #endif
  334. #define SCNo16                     "ho"
  335. #define SCNo32                      "o"
  336. #if _LONG_LONG
  337. #define SCNo64                    "llo"
  338. #endif
  339. #define SCNu16                     "hu"
  340. #define SCNu32                      "u"
  341. #if _LONG_LONG
  342. #define SCNu64                    "llu"
  343. #endif
  344. #define SCNx16                     "hx"
  345. #define SCNx32                      "x"
  346. #if _LONG_LONG
  347. #define SCNx64                    "llx"
  348. #endif
  349. #define SCNdFAST16                  "d"
  350. #define SCNdFAST32                  "d"
  351. #if _LONG_LONG
  352. #define SCNdFAST64                "lld"
  353. #endif
  354. #define SCNdLEAST16                 "d"
  355. #define SCNdLEAST32                 "d"
  356. #if _LONG_LONG
  357. #define SCNdLEAST64               "lld"
  358. #endif
  359. #define SCNiFAST16                  "i"
  360. #define SCNiFAST32                  "i"
  361. #if _LONG_LONG
  362. #define SCNiFAST64                "lli"
  363. #endif
  364. #define SCNiLEAST16                 "i"
  365. #define SCNiLEAST32                 "i"
  366. #if _LONG_LONG
  367. #define SCNiLEAST64               "lli"
  368. #endif
  369. #define SCNoFAST16                  "o"
  370. #define SCNoFAST32                  "o"
  371. #if _LONG_LONG
  372. #define SCNoFAST64                "llo"
  373. #endif
  374. #define SCNoLEAST16                 "o"
  375. #define SCNoLEAST32                 "o"
  376. #if _LONG_LONG
  377. #define SCNoLEAST64               "llo"
  378. #endif
  379. #define SCNuFAST16                  "u"
  380. #define SCNuFAST32                  "u"
  381. #if _LONG_LONG
  382. #define SCNuFAST64                "llu"
  383. #endif
  384. #define SCNuLEAST16                 "u"
  385. #define SCNuLEAST32                 "u"
  386. #if _LONG_LONG
  387. #define SCNuLEAST64               "llu"
  388. #endif
  389. #define SCNxFAST16                  "x"
  390. #define SCNxFAST32                  "x"
  391. #if _LONG_LONG
  392. #define SCNxFAST64                "llx"
  393. #endif
  394. #define SCNxLEAST16                 "x"
  395. #define SCNxLEAST32                 "x"
  396. #if _LONG_LONG
  397. #define SCNxLEAST64               "llx"
  398. #endif
  399. #define SCNXFAST16                  "X"
  400. #define SCNXFAST32                  "X"
  401. #if _LONG_LONG
  402. #define SCNXFAST64                "llX"
  403. #endif
  404. #define SCNXLEAST16                 "X"
  405. #define SCNXLEAST32                 "X"
  406. #if _LONG_LONG
  407. #define SCNXLEAST64               "llX"
  408. #endif
  409.  
  410.  
  411. /* The following macros define I/O formats for intmax_t and uintmax_t.
  412. */
  413.  
  414. #define PRIdMAX                   "lld"
  415. #define PRIiMAX                   "lli"
  416. #define PRIoMAX                   "llo"
  417. #define PRIxMAX                   "llx"
  418. #define PRIXMAX                   "llX"
  419. #define PRIuMAX                   "llu"
  420. #define SCNiMAX                   "lli"
  421. #define SCNdMAX                   "lld"
  422. #define SCNoMAX                   "llo"
  423. #define SCNxMAX                   "llx"
  424. #define SCNuMAX                   "llu"
  425.  
  426. /* The following macros define I/O formats for intfast_t and uintfast_t.
  427. */
  428.  
  429. #define PRIdFAST                    "d"
  430. #define PRIiFAST                    "i"
  431. #define PRIoFAST                    "o"
  432. #define PRIxFAST                    "x"
  433. #define PRIXFAST                    "X"
  434. #define PRIuFAST                    "u"
  435. #define SCNiFAST                    "i"
  436. #define SCNdFAST                    "d"
  437. #define SCNoFAST                    "o"
  438. #define SCNxFAST                    "x"
  439. #define SCNuFAST                    "u"
  440.  
  441.  
  442. /*************** conversion functions ********************************
  443. **
  444. ** The following routines are proposed to do conversions from strings to the
  445. ** largest supported integer types. They parallel the ISO C strto* functions.
  446. */
  447.  
  448. extern intmax_t strtoimax (const char *, char**, int);
  449. extern uintmax_t strtoumax (const char *, char**, int);
  450.  
  451. #ifdef _LONG_LONG
  452.    #ifdef __OS2__
  453.       #pragma map(strtoimax, "strtoll")
  454.       #pragma map(strtoumax, "strtoull")
  455.    #else
  456.       #pragma map(strtoimax, "?strtoll")
  457.       #pragma map(strtoumax, "?strtoull")
  458.    #endif
  459. #else
  460.    #ifdef __OS2__
  461.       #pragma map(strtoimax, "strtol")
  462.       #pragma map(strtoumax, "strtoul")
  463.    #else
  464.       #pragma map(strtoimax, "?strtol")
  465.       #pragma map(strtoumax, "?strtoul")
  466.    #endif
  467. #endif
  468.  
  469. #ifdef __cplusplus
  470.    }
  471. #endif
  472.  
  473.