The official µGFX library repository. http://ugfx.io

gfx_types.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * This file is subject to the terms of the GFX License. If a copy of
  3. * the license was not distributed with this file, you can obtain one at:
  4. *
  5. * http://ugfx.io/license.html
  6. */
  7. // Safety first!
  8. #if (!defined(__STDC__) || !__STDC__) && !defined(__cplusplus) && !defined(_MSC_VER)
  9. #error "K&R C Compilers are not supported. Try turning on ANSI C compliance or at least defining macro __STDC__=1"
  10. #endif
  11. // This guarantees definition (even in C89) of:
  12. // offsetof(s, m) - required and compiler dependant
  13. // size_t - we try not to use this in uGFX as it may be 64 bit
  14. // NULL - globally useful
  15. // ptrdiff_t - globally useful
  16. #include <stddef.h>
  17. #if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )
  18. #include <stdint.h>
  19. typedef int_least8_t gI8;
  20. typedef uint_least8_t gU8;
  21. typedef int_least16_t gI16;
  22. typedef uint_least16_t gU16;
  23. typedef int_least32_t gI32;
  24. typedef uint_least32_t gU32;
  25. #define GI8_C(v) INT8_C(v)
  26. #define GU8_C(v) UINT8_C(v)
  27. #define GI16_C(v) INT16_C(v)
  28. #define GU16_C(v) UINT16_C(v)
  29. #define GI32_C(v) INT32_C(v)
  30. #define GU32_C(v) UINT32_C(v)
  31. #ifdef INT64_C
  32. typedef int_least64_t gI64;
  33. typedef uint_least64_t gU64;
  34. #define GI64_C(v) INT64_C(v)
  35. #define GU64_C(v) UINT64_C(v)
  36. #define GFX_TYPE_64 GFXON
  37. #else
  38. #define GFX_TYPE_64 GFXOFF
  39. #endif
  40. #elif defined(_MSC_VER)
  41. #if (_MSC_VER < 1300)
  42. typedef signed char gI8;
  43. typedef unsigned char gU8;
  44. typedef signed short gI16;
  45. typedef unsigned short gU16;
  46. typedef signed int gI32;
  47. typedef unsigned int gU32;
  48. #else
  49. typedef signed __int8 gI8;
  50. typedef unsigned __int8 gU8;
  51. typedef signed __int16 gI16;
  52. typedef unsigned __int16 gU16;
  53. typedef signed __int32 gI32;
  54. typedef unsigned __int32 gU32;
  55. #endif
  56. typedef signed __int64 gI64;
  57. typedef unsigned __int64 gU64;
  58. #define GI8_C(v) v ## i8
  59. #define GU8_C(v) v ## ui8
  60. #define GI16_C(v) v ## i16
  61. #define GU16_C(v) v ## ui16
  62. #define GI32_C(v) v ## i32
  63. #define GU32_C(v) v ## ui32
  64. #define GI64_C(v) v ## i64
  65. #define GU64_C(v) v ## ui64
  66. #define GFX_TYPE_64 GFXON
  67. /*#elif defined(__GNUC__) || defined(__GNUG__)
  68. typedef __INT8_TYPE__ gI8;
  69. typedef __UINT8_TYPE__ gU8;
  70. typedef __INT16_TYPE__ gI16;
  71. typedef __UINT16_TYPE__ gU16;
  72. typedef __INT32_TYPE__ gI32;
  73. typedef __UINT32_TYPE__ gU32;
  74. #define GI8_C(v) v
  75. #define GU8_C(v) v ## U
  76. #define GI16_C(v) v
  77. #define GU16_C(v) v ## U
  78. #define GI32_C(v) v
  79. #define GU32_C(v) v ## U
  80. #define GFX_TYPE_64 GFXOFF
  81. */
  82. #else
  83. #include <limits.h>
  84. /* char's are the smallest common type definition */
  85. typedef signed char gI8;
  86. typedef unsigned char gU8;
  87. #define GI8_C(v) v
  88. #define GU8_C(v) v ## U
  89. /*
  90. * Deduce the type assignments from limits.h under the assumption that
  91. * integer sizes in bits are powers of 2, and follow the ANSI
  92. * definitions.
  93. */
  94. #if defined(SHRT_MAX) && SHRT_MAX >= 0x7FFF
  95. typedef signed short gI16
  96. typedef unsigned short gU16
  97. #else
  98. typedef signed int gI16
  99. typedef unsigned int gU16
  100. #endif
  101. #define GI16_C(v) v
  102. #define GU16_C(v) v ## U
  103. #if defined(INT_MAX) && INT_MAX >= 0x7FFFFFFL
  104. typedef signed int gI32
  105. typedef unsigned int gU32
  106. #define GI32_C(v) v
  107. #define GU32_C(v) v ## U
  108. #else
  109. typedef signed long gI32
  110. typedef unsigned long gU32
  111. #define GI32_C(v) v ## L
  112. #define GU32_C(v) v ## UL
  113. #endif
  114. #if defined(__GNUC__) && !defined(vxWorks)
  115. #define GFX_TYPE_64 GFXON
  116. __extension__ typedef long long gI64;
  117. __extension__ typedef unsigned long long gU64;
  118. #define GI64_C(v) v ## LL
  119. #define GU64_C(v) v ## ULL
  120. #elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
  121. #define GFX_TYPE_64 GFXON
  122. typedef long long gI64;
  123. typedef unsigned long long gU64;
  124. #define GI64_C(v) v ## LL
  125. #define GU64_C(v) v ## ULL
  126. #elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
  127. #define GFX_TYPE_64 GFXON
  128. typedef signed __int64 gI64;
  129. typedef unsigned __int64 gU64;
  130. #else
  131. #define GFX_TYPE_64 GFXOFF
  132. #endif
  133. #endif
  134. typedef void * gAny;
  135. typedef void * gPtr;
  136. typedef ptrdiff_t gPtrDiff;
  137. #if GFX_MEM_LT64K
  138. typedef gU16 gMemSize;
  139. #else
  140. typedef gU32 gMemSize;
  141. #endif
  142. typedef gI32 gFileSize;
  143. typedef gI8 gBool;
  144. #define gTrue (-1)
  145. #define gFalse (0)
  146. #if GFX_COMPAT_V2
  147. /* Is stdint.h already included? */
  148. #ifndef INT16_C
  149. typedef gI8 int8_t;
  150. typedef gU8 uint8_t;
  151. typedef gI16 int16_t;
  152. typedef gU16 uint16_t;
  153. typedef gI32 int32_t;
  154. typedef gU32 uint32_t;
  155. #endif
  156. typedef gI8 bool_t;
  157. #ifndef TRUE
  158. #define TRUE gTrue
  159. #endif
  160. #ifndef FALSE
  161. #define FALSE gFalse
  162. #endif
  163. #endif