fixedint.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Portable header to provide the 32 and 64 bits type.
  3. Not a compatible replacement for <stdint.h>, do not blindly use it as such.
  4. */
  5. #if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined(__UINT_FAST64_TYPE__)) )) && !defined(FIXEDINT_H_INCLUDED)
  6. #include <stdint.h>
  7. #define FIXEDINT_H_INCLUDED
  8. #if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C)
  9. #include <limits.h>
  10. #define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
  11. #endif
  12. #endif
  13. #ifndef FIXEDINT_H_INCLUDED
  14. #define FIXEDINT_H_INCLUDED
  15. #include <limits.h>
  16. /* (u)int32_t */
  17. #ifndef uint32_t
  18. #if (ULONG_MAX == 0xffffffffUL)
  19. typedef unsigned long uint32_t;
  20. #elif (UINT_MAX == 0xffffffffUL)
  21. typedef unsigned int uint32_t;
  22. #elif (USHRT_MAX == 0xffffffffUL)
  23. typedef unsigned short uint32_t;
  24. #endif
  25. #endif
  26. #ifndef int32_t
  27. #if (LONG_MAX == 0x7fffffffL)
  28. typedef signed long int32_t;
  29. #elif (INT_MAX == 0x7fffffffL)
  30. typedef signed int int32_t;
  31. #elif (SHRT_MAX == 0x7fffffffL)
  32. typedef signed short int32_t;
  33. #endif
  34. #endif
  35. /* (u)int64_t */
  36. #if (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && __STDC_VERSION__ >= 199901L)
  37. typedef long long int64_t;
  38. typedef unsigned long long uint64_t;
  39. #define UINT64_C(v) v ##ULL
  40. #define INT64_C(v) v ##LL
  41. #elif defined(__GNUC__)
  42. __extension__ typedef long long int64_t;
  43. __extension__ typedef unsigned long long uint64_t;
  44. #define UINT64_C(v) v ##ULL
  45. #define INT64_C(v) v ##LL
  46. #elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC)
  47. typedef long long int64_t;
  48. typedef unsigned long long uint64_t;
  49. #define UINT64_C(v) v ##ULL
  50. #define INT64_C(v) v ##LL
  51. #elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || defined(__DECC)
  52. typedef __int64 int64_t;
  53. typedef unsigned __int64 uint64_t;
  54. #define UINT64_C(v) v ##UI64
  55. #define INT64_C(v) v ##I64
  56. #endif
  57. #endif