stdint.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WAMR_LIBC_STDINT_H
  6. #define _WAMR_LIBC_STDINT_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /* clang-format off */
  11. /* The word size of platform */
  12. #ifdef __wasm64__
  13. #define __WORDSIZE 64
  14. #else
  15. #define __WORDSIZE 32
  16. #endif
  17. typedef char int8_t;
  18. typedef short int int16_t;
  19. typedef int int32_t;
  20. typedef long long int int64_t;
  21. /* Unsigned. */
  22. typedef unsigned char uint8_t;
  23. typedef unsigned short int uint16_t;
  24. typedef unsigned int uint32_t;
  25. typedef unsigned long long int uint64_t;
  26. typedef __INTPTR_TYPE__ intptr_t;
  27. typedef __UINTPTR_TYPE__ uintptr_t;
  28. /* Signed and unsigned */
  29. #if __WORDSIZE == 64
  30. #define INT64_C(c) c ## L
  31. #define UINT64_C(c) c ## UL
  32. #define INTMAX_C(c) c ## L
  33. #define UINTMAX_C(c) c ## UL
  34. #else
  35. #define INT64_C(c) c ## LL
  36. #define UINT64_C(c) c ## ULL
  37. #define INTMAX_C(c) c ## LL
  38. #define UINTMAX_C(c) c ## ULL
  39. #endif
  40. /* Minimum of signed integral types. */
  41. # define INT8_MIN (-128)
  42. # define INT16_MIN (-32767-1)
  43. # define INT32_MIN (-2147483647-1)
  44. # define INT64_MIN (-INT64_C(9223372036854775807)-1)
  45. /* Maximum of signed integral types. */
  46. # define INT8_MAX (127)
  47. # define INT16_MAX (32767)
  48. # define INT32_MAX (2147483647)
  49. # define INT64_MAX (INT64_C(9223372036854775807))
  50. /* Maximum of unsigned integral types. */
  51. # define UINT8_MAX (255)
  52. # define UINT16_MAX (65535)
  53. # define UINT32_MAX (4294967295U)
  54. # define UINT64_MAX (UINT64_C(18446744073709551615))
  55. /* Values to test for integral types holding `void *' pointer. */
  56. #if __WORDSIZE == 64
  57. #define INTPTR_MIN INT64_MIN
  58. #define INTPTR_MAX INT64_MAX
  59. #define UINTPTR_MAX UINT64_MAX
  60. #else
  61. #define INTPTR_MIN INT32_MIN
  62. #define INTPTR_MAX INT32_MAX
  63. #define UINTPTR_MAX UINT32_MAX
  64. #endif
  65. /* Limit of `size_t' type. */
  66. #if __WORDSIZE == 64
  67. #define SIZE_MAX UINT64_MAX
  68. #else
  69. #define SIZE_MAX UINT32_MAX
  70. #endif
  71. /* clang-format on */
  72. #ifdef __cplusplus
  73. }
  74. #endif
  75. #endif