integer-types.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /****************************************************************************
  2. *
  3. * config/integer-types.h
  4. *
  5. * FreeType integer types definitions.
  6. *
  7. * Copyright (C) 1996-2023 by
  8. * David Turner, Robert Wilhelm, and Werner Lemberg.
  9. *
  10. * This file is part of the FreeType project, and may only be used,
  11. * modified, and distributed under the terms of the FreeType project
  12. * license, LICENSE.TXT. By continuing to use, modify, or distribute
  13. * this file you indicate that you have read the license and
  14. * understand and accept it fully.
  15. *
  16. */
  17. #ifndef FREETYPE_CONFIG_INTEGER_TYPES_H_
  18. #define FREETYPE_CONFIG_INTEGER_TYPES_H_
  19. /* There are systems (like the Texas Instruments 'C54x) where a `char` */
  20. /* has 16~bits. ANSI~C says that `sizeof(char)` is always~1. Since an */
  21. /* `int` has 16~bits also for this system, `sizeof(int)` gives~1 which */
  22. /* is probably unexpected. */
  23. /* */
  24. /* `CHAR_BIT` (defined in `limits.h`) gives the number of bits in a */
  25. /* `char` type. */
  26. #ifndef FT_CHAR_BIT
  27. #define FT_CHAR_BIT CHAR_BIT
  28. #endif
  29. #ifndef FT_SIZEOF_INT
  30. /* The size of an `int` type. */
  31. #if FT_UINT_MAX == 0xFFFFUL
  32. #define FT_SIZEOF_INT ( 16 / FT_CHAR_BIT )
  33. #elif FT_UINT_MAX == 0xFFFFFFFFUL
  34. #define FT_SIZEOF_INT ( 32 / FT_CHAR_BIT )
  35. #elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL
  36. #define FT_SIZEOF_INT ( 64 / FT_CHAR_BIT )
  37. #else
  38. #error "Unsupported size of `int' type!"
  39. #endif
  40. #endif /* !defined(FT_SIZEOF_INT) */
  41. #ifndef FT_SIZEOF_LONG
  42. /* The size of a `long` type. A five-byte `long` (as used e.g. on the */
  43. /* DM642) is recognized but avoided. */
  44. #if FT_ULONG_MAX == 0xFFFFFFFFUL
  45. #define FT_SIZEOF_LONG ( 32 / FT_CHAR_BIT )
  46. #elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL
  47. #define FT_SIZEOF_LONG ( 32 / FT_CHAR_BIT )
  48. #elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL
  49. #define FT_SIZEOF_LONG ( 64 / FT_CHAR_BIT )
  50. #else
  51. #error "Unsupported size of `long' type!"
  52. #endif
  53. #endif /* !defined(FT_SIZEOF_LONG) */
  54. #ifndef FT_SIZEOF_LONG_LONG
  55. /* The size of a `long long` type if available */
  56. #if defined( FT_ULLONG_MAX ) && FT_ULLONG_MAX >= 0xFFFFFFFFFFFFFFFFULL
  57. #define FT_SIZEOF_LONG_LONG ( 64 / FT_CHAR_BIT )
  58. #else
  59. #define FT_SIZEOF_LONG_LONG 0
  60. #endif
  61. #endif /* !defined(FT_SIZEOF_LONG_LONG) */
  62. /**************************************************************************
  63. *
  64. * @section:
  65. * basic_types
  66. *
  67. */
  68. /**************************************************************************
  69. *
  70. * @type:
  71. * FT_Int16
  72. *
  73. * @description:
  74. * A typedef for a 16bit signed integer type.
  75. */
  76. typedef signed short FT_Int16;
  77. /**************************************************************************
  78. *
  79. * @type:
  80. * FT_UInt16
  81. *
  82. * @description:
  83. * A typedef for a 16bit unsigned integer type.
  84. */
  85. typedef unsigned short FT_UInt16;
  86. /* */
  87. /* this #if 0 ... #endif clause is for documentation purposes */
  88. #if 0
  89. /**************************************************************************
  90. *
  91. * @type:
  92. * FT_Int32
  93. *
  94. * @description:
  95. * A typedef for a 32bit signed integer type. The size depends on the
  96. * configuration.
  97. */
  98. typedef signed XXX FT_Int32;
  99. /**************************************************************************
  100. *
  101. * @type:
  102. * FT_UInt32
  103. *
  104. * A typedef for a 32bit unsigned integer type. The size depends on the
  105. * configuration.
  106. */
  107. typedef unsigned XXX FT_UInt32;
  108. /**************************************************************************
  109. *
  110. * @type:
  111. * FT_Int64
  112. *
  113. * A typedef for a 64bit signed integer type. The size depends on the
  114. * configuration. Only defined if there is real 64bit support;
  115. * otherwise, it gets emulated with a structure (if necessary).
  116. */
  117. typedef signed XXX FT_Int64;
  118. /**************************************************************************
  119. *
  120. * @type:
  121. * FT_UInt64
  122. *
  123. * A typedef for a 64bit unsigned integer type. The size depends on the
  124. * configuration. Only defined if there is real 64bit support;
  125. * otherwise, it gets emulated with a structure (if necessary).
  126. */
  127. typedef unsigned XXX FT_UInt64;
  128. /* */
  129. #endif
  130. #if FT_SIZEOF_INT == ( 32 / FT_CHAR_BIT )
  131. typedef signed int FT_Int32;
  132. typedef unsigned int FT_UInt32;
  133. #elif FT_SIZEOF_LONG == ( 32 / FT_CHAR_BIT )
  134. typedef signed long FT_Int32;
  135. typedef unsigned long FT_UInt32;
  136. #else
  137. #error "no 32bit type found -- please check your configuration files"
  138. #endif
  139. /* look up an integer type that is at least 32~bits */
  140. #if FT_SIZEOF_INT >= ( 32 / FT_CHAR_BIT )
  141. typedef int FT_Fast;
  142. typedef unsigned int FT_UFast;
  143. #elif FT_SIZEOF_LONG >= ( 32 / FT_CHAR_BIT )
  144. typedef long FT_Fast;
  145. typedef unsigned long FT_UFast;
  146. #endif
  147. /* determine whether we have a 64-bit integer type */
  148. #if FT_SIZEOF_LONG == ( 64 / FT_CHAR_BIT )
  149. #define FT_INT64 long
  150. #define FT_UINT64 unsigned long
  151. #elif FT_SIZEOF_LONG_LONG >= ( 64 / FT_CHAR_BIT )
  152. #define FT_INT64 long long int
  153. #define FT_UINT64 unsigned long long int
  154. /**************************************************************************
  155. *
  156. * A 64-bit data type may create compilation problems if you compile in
  157. * strict ANSI mode. To avoid them, we disable other 64-bit data types if
  158. * `__STDC__` is defined. You can however ignore this rule by defining the
  159. * `FT_CONFIG_OPTION_FORCE_INT64` configuration macro.
  160. */
  161. #elif !defined( __STDC__ ) || defined( FT_CONFIG_OPTION_FORCE_INT64 )
  162. #if defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */
  163. /* this compiler provides the `__int64` type */
  164. #define FT_INT64 __int64
  165. #define FT_UINT64 unsigned __int64
  166. #elif defined( __BORLANDC__ ) /* Borland C++ */
  167. /* XXXX: We should probably check the value of `__BORLANDC__` in order */
  168. /* to test the compiler version. */
  169. /* this compiler provides the `__int64` type */
  170. #define FT_INT64 __int64
  171. #define FT_UINT64 unsigned __int64
  172. #elif defined( __WATCOMC__ ) && __WATCOMC__ >= 1100 /* Watcom C++ */
  173. #define FT_INT64 long long int
  174. #define FT_UINT64 unsigned long long int
  175. #elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */
  176. #define FT_INT64 long long int
  177. #define FT_UINT64 unsigned long long int
  178. #elif defined( __GNUC__ )
  179. /* GCC provides the `long long` type */
  180. #define FT_INT64 long long int
  181. #define FT_UINT64 unsigned long long int
  182. #endif /* !__STDC__ */
  183. #endif /* FT_SIZEOF_LONG == (64 / FT_CHAR_BIT) */
  184. #ifdef FT_INT64
  185. typedef FT_INT64 FT_Int64;
  186. typedef FT_UINT64 FT_UInt64;
  187. #endif
  188. #endif /* FREETYPE_CONFIG_INTEGER_TYPES_H_ */