stdint.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Some ISO C99/C++11 integer types + Generic integer types
  2. // This file introduces definitions to the global namespace!
  3. //
  4. // Platform: ISO C++ 98/11
  5. // $Id$
  6. //
  7. // (c) __vic 2006
  8. #ifndef __VIC_STDINT_H
  9. #define __VIC_STDINT_H
  10. #include<__vic/defs.h>
  11. #if __cplusplus >= 201103L
  12. #include<cstdint>
  13. #elif defined(_MSC_VER) && _MSC_VER < 1600 || \
  14. defined(__BORLANDC__) && __BORLANDC__ < 0x0580
  15. // Exact-width integer types
  16. typedef signed char int8_t;
  17. typedef short int int16_t;
  18. typedef int int32_t;
  19. typedef __int64 int64_t;
  20. typedef unsigned char uint8_t;
  21. typedef unsigned short int uint16_t;
  22. typedef unsigned int uint32_t;
  23. typedef unsigned __int64 uint64_t;
  24. // Minimum-width integer types
  25. typedef int8_t int_least8_t;
  26. typedef int16_t int_least16_t;
  27. typedef int32_t int_least32_t;
  28. typedef int64_t int_least64_t;
  29. typedef uint8_t uint_least8_t;
  30. typedef uint16_t uint_least16_t;
  31. typedef uint32_t uint_least32_t;
  32. typedef uint64_t uint_least64_t;
  33. // Fastest minimum-width integer types
  34. typedef int8_t int_fast8_t;
  35. typedef int32_t int_fast16_t;
  36. typedef int32_t int_fast32_t;
  37. typedef int64_t int_fast64_t;
  38. typedef uint8_t uint_fast8_t;
  39. typedef uint32_t uint_fast16_t;
  40. typedef uint32_t uint_fast32_t;
  41. typedef uint64_t uint_fast64_t;
  42. // Integer types capable of holding object pointers
  43. // See below...
  44. #define __VIC_NEED_INTPTR_T 1
  45. // Greatest-width integer types
  46. typedef int64_t intmax_t;
  47. typedef uint64_t uintmax_t;
  48. #else // just redirect to the system header
  49. #if defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
  50. #include<inttypes.h>
  51. #else
  52. #include<stdint.h>
  53. #endif
  54. #endif
  55. namespace __vic {
  56. // Integers with exactly specified size
  57. template<unsigned > struct int_exactly_bytes; // not defined
  58. template<unsigned > struct uint_exactly_bytes; // not defined
  59. // Specializations
  60. template<> struct int_exactly_bytes<1U> { typedef int8_t type; };
  61. template<> struct int_exactly_bytes<2U> { typedef int16_t type; };
  62. template<> struct int_exactly_bytes<4U> { typedef int32_t type; };
  63. template<> struct int_exactly_bytes<8U> { typedef int64_t type; };
  64. template<> struct uint_exactly_bytes<1U> { typedef uint8_t type; };
  65. template<> struct uint_exactly_bytes<2U> { typedef uint16_t type; };
  66. template<> struct uint_exactly_bytes<4U> { typedef uint32_t type; };
  67. template<> struct uint_exactly_bytes<8U> { typedef uint64_t type; };
  68. #if __cpp_alias_templates
  69. template<unsigned N> using int_exact_bytes = typename int_exactly_bytes<N>::type;
  70. template<unsigned N> using uint_exact_bytes = typename uint_exactly_bytes<N>::type;
  71. #endif
  72. } // namespace
  73. #ifdef __VIC_NEED_INTPTR_T
  74. typedef __vic::int_exactly_bytes<sizeof(void*)>::type intptr_t;
  75. typedef __vic::uint_exactly_bytes<sizeof(void*)>::type uintptr_t;
  76. #undef __VIC_NEED_INTPTR_T
  77. #endif
  78. #endif // header guard