platform.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. // Copyright (C) 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 1997-2016, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. *
  11. * FILE NAME : platform.h
  12. *
  13. * Date Name Description
  14. * 05/13/98 nos Creation (content moved here from ptypes.h).
  15. * 03/02/99 stephen Added AS400 support.
  16. * 03/30/99 stephen Added Linux support.
  17. * 04/13/99 stephen Reworked for autoconf.
  18. ******************************************************************************
  19. */
  20. #ifndef _PLATFORM_H
  21. #define _PLATFORM_H
  22. #include "unicode/uconfig.h"
  23. #include "unicode/uvernum.h"
  24. /**
  25. * \file
  26. * \brief Basic types for the platform.
  27. *
  28. * This file used to be generated by autoconf/configure.
  29. * Starting with ICU 49, platform.h is a normal source file,
  30. * to simplify cross-compiling and working with non-autoconf/make build systems.
  31. *
  32. * When a value in this file does not work on a platform, then please
  33. * try to derive it from the U_PLATFORM value
  34. * (for which we might need a new value constant in rare cases)
  35. * and/or from other macros that are predefined by the compiler
  36. * or defined in standard (POSIX or platform or compiler) headers.
  37. *
  38. * As a temporary workaround, you can add an explicit <code>#define</code> for some macros
  39. * before it is first tested, or add an equivalent -D macro definition
  40. * to the compiler's command line.
  41. *
  42. * Note: Some compilers provide ways to show the predefined macros.
  43. * For example, with gcc you can compile an empty .c file and have the compiler
  44. * print the predefined macros with
  45. * \code
  46. * gcc -E -dM -x c /dev/null | sort
  47. * \endcode
  48. * (You can provide an actual empty .c file rather than /dev/null.
  49. * <code>-x c++</code> is for C++.)
  50. */
  51. /**
  52. * Define some things so that they can be documented.
  53. * @internal
  54. */
  55. #ifdef U_IN_DOXYGEN
  56. /*
  57. * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented.
  58. * Solution: #define any defines for non @internal API here, so that they are visible in the docs. If you just set PREDEFINED in Doxyfile.in, they won't be documented.
  59. */
  60. /* None for now. */
  61. #endif
  62. /**
  63. * \def U_PLATFORM
  64. * The U_PLATFORM macro defines the platform we're on.
  65. *
  66. * We used to define one different, value-less macro per platform.
  67. * That made it hard to know the set of relevant platforms and macros,
  68. * and hard to deal with variants of platforms.
  69. *
  70. * Starting with ICU 49, we define platforms as numeric macros,
  71. * with ranges of values for related platforms and their variants.
  72. * The U_PLATFORM macro is set to one of these values.
  73. *
  74. * Historical note from the Solaris Wikipedia article:
  75. * AT&T and Sun collaborated on a project to merge the most popular Unix variants
  76. * on the market at that time: BSD, System V, and Xenix.
  77. * This became Unix System V Release 4 (SVR4).
  78. *
  79. * @internal
  80. */
  81. /** Unknown platform. @internal */
  82. #define U_PF_UNKNOWN 0
  83. /** Windows @internal */
  84. #define U_PF_WINDOWS 1000
  85. /** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */
  86. #define U_PF_MINGW 1800
  87. /**
  88. * Cygwin. Windows, calls to cygwin1.dll for Posix functions,
  89. * using MSVC or GNU gcc and binutils.
  90. * @internal
  91. */
  92. #define U_PF_CYGWIN 1900
  93. /* Reserve 2000 for U_PF_UNIX? */
  94. /** HP-UX is based on UNIX System V. @internal */
  95. #define U_PF_HPUX 2100
  96. /** Solaris is a Unix operating system based on SVR4. @internal */
  97. #define U_PF_SOLARIS 2600
  98. /** BSD is a UNIX operating system derivative. @internal */
  99. #define U_PF_BSD 3000
  100. /** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */
  101. #define U_PF_AIX 3100
  102. /** IRIX is based on UNIX System V with BSD extensions. @internal */
  103. #define U_PF_IRIX 3200
  104. /**
  105. * Darwin is a POSIX-compliant operating system, composed of code developed by Apple,
  106. * as well as code derived from NeXTSTEP, BSD, and other projects,
  107. * built around the Mach kernel.
  108. * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based.
  109. * (Original description modified from WikiPedia.)
  110. * @internal
  111. */
  112. #define U_PF_DARWIN 3500
  113. /** iPhone OS (iOS) is a derivative of Mac OS X. @internal */
  114. #define U_PF_IPHONE 3550
  115. /** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */
  116. #define U_PF_QNX 3700
  117. /** Linux is a Unix-like operating system. @internal */
  118. #define U_PF_LINUX 4000
  119. /**
  120. * Native Client is pretty close to Linux.
  121. * See https://developer.chrome.com/native-client and
  122. * http://www.chromium.org/nativeclient
  123. * @internal
  124. */
  125. #define U_PF_BROWSER_NATIVE_CLIENT 4020
  126. /** Android is based on Linux. @internal */
  127. #define U_PF_ANDROID 4050
  128. /* Maximum value for Linux-based platform is 4499 */
  129. /** z/OS is the successor to OS/390 which was the successor to MVS. @internal */
  130. #define U_PF_OS390 9000
  131. /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */
  132. #define U_PF_OS400 9400
  133. #ifdef U_PLATFORM
  134. /* Use the predefined value. */
  135. #elif defined(__MINGW32__)
  136. # define U_PLATFORM U_PF_MINGW
  137. #elif defined(__CYGWIN__)
  138. # define U_PLATFORM U_PF_CYGWIN
  139. #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
  140. # define U_PLATFORM U_PF_WINDOWS
  141. #elif defined(__ANDROID__)
  142. # define U_PLATFORM U_PF_ANDROID
  143. /* Android wchar_t support depends on the API level. */
  144. # include <android/api-level.h>
  145. #elif defined(__native_client__)
  146. # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
  147. #elif defined(linux) || defined(__linux__) || defined(__linux)
  148. # define U_PLATFORM U_PF_LINUX
  149. #elif defined(__APPLE__) && defined(__MACH__)
  150. # include <TargetConditionals.h>
  151. # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
  152. # define U_PLATFORM U_PF_IPHONE
  153. # else
  154. # define U_PLATFORM U_PF_DARWIN
  155. # endif
  156. #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
  157. # if defined(__FreeBSD__)
  158. # include <sys/endian.h>
  159. # endif
  160. # define U_PLATFORM U_PF_BSD
  161. #elif defined(sun) || defined(__sun)
  162. /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
  163. # define U_PLATFORM U_PF_SOLARIS
  164. # if defined(__GNUC__)
  165. /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
  166. * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
  167. * is included which does not include this header file.
  168. */
  169. # include <sys/isa_defs.h>
  170. # endif
  171. #elif defined(_AIX) || defined(__TOS_AIX__)
  172. # define U_PLATFORM U_PF_AIX
  173. #elif defined(_hpux) || defined(hpux) || defined(__hpux)
  174. # define U_PLATFORM U_PF_HPUX
  175. #elif defined(sgi) || defined(__sgi)
  176. # define U_PLATFORM U_PF_IRIX
  177. #elif defined(__QNX__) || defined(__QNXNTO__)
  178. # define U_PLATFORM U_PF_QNX
  179. #elif defined(__TOS_MVS__)
  180. # define U_PLATFORM U_PF_OS390
  181. #elif defined(__OS400__) || defined(__TOS_OS400__)
  182. # define U_PLATFORM U_PF_OS400
  183. #else
  184. # define U_PLATFORM U_PF_UNKNOWN
  185. #endif
  186. /**
  187. * \def CYGWINMSVC
  188. * Defined if this is Windows with Cygwin, but using MSVC rather than gcc.
  189. * Otherwise undefined.
  190. * @internal
  191. */
  192. /* Commented out because this is already set in mh-cygwin-msvc
  193. #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
  194. # define CYGWINMSVC
  195. #endif
  196. */
  197. /**
  198. * \def U_PLATFORM_USES_ONLY_WIN32_API
  199. * Defines whether the platform uses only the Win32 API.
  200. * Set to 1 for Windows/MSVC and MinGW but not Cygwin.
  201. * @internal
  202. */
  203. #ifdef U_PLATFORM_USES_ONLY_WIN32_API
  204. /* Use the predefined value. */
  205. #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
  206. # define U_PLATFORM_USES_ONLY_WIN32_API 1
  207. #else
  208. /* Cygwin implements POSIX. */
  209. # define U_PLATFORM_USES_ONLY_WIN32_API 0
  210. #endif
  211. /**
  212. * \def U_PLATFORM_HAS_WIN32_API
  213. * Defines whether the Win32 API is available on the platform.
  214. * Set to 1 for Windows/MSVC, MinGW and Cygwin.
  215. * @internal
  216. */
  217. #ifdef U_PLATFORM_HAS_WIN32_API
  218. /* Use the predefined value. */
  219. #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  220. # define U_PLATFORM_HAS_WIN32_API 1
  221. #else
  222. # define U_PLATFORM_HAS_WIN32_API 0
  223. #endif
  224. /**
  225. * \def U_PLATFORM_IMPLEMENTS_POSIX
  226. * Defines whether the platform implements (most of) the POSIX API.
  227. * Set to 1 for Cygwin and most other platforms.
  228. * @internal
  229. */
  230. #ifdef U_PLATFORM_IMPLEMENTS_POSIX
  231. /* Use the predefined value. */
  232. #elif U_PLATFORM_USES_ONLY_WIN32_API
  233. # define U_PLATFORM_IMPLEMENTS_POSIX 0
  234. #else
  235. # define U_PLATFORM_IMPLEMENTS_POSIX 1
  236. #endif
  237. /**
  238. * \def U_PLATFORM_IS_LINUX_BASED
  239. * Defines whether the platform is Linux or one of its derivatives.
  240. * @internal
  241. */
  242. #ifdef U_PLATFORM_IS_LINUX_BASED
  243. /* Use the predefined value. */
  244. #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
  245. # define U_PLATFORM_IS_LINUX_BASED 1
  246. #else
  247. # define U_PLATFORM_IS_LINUX_BASED 0
  248. #endif
  249. /**
  250. * \def U_PLATFORM_IS_DARWIN_BASED
  251. * Defines whether the platform is Darwin or one of its derivatives.
  252. * @internal
  253. */
  254. #ifdef U_PLATFORM_IS_DARWIN_BASED
  255. /* Use the predefined value. */
  256. #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
  257. # define U_PLATFORM_IS_DARWIN_BASED 1
  258. #else
  259. # define U_PLATFORM_IS_DARWIN_BASED 0
  260. #endif
  261. /**
  262. * \def U_HAVE_STDINT_H
  263. * Defines whether stdint.h is available. It is a C99 standard header.
  264. * We used to include inttypes.h which includes stdint.h but we usually do not need
  265. * the additional definitions from inttypes.h.
  266. * @internal
  267. */
  268. #ifdef U_HAVE_STDINT_H
  269. /* Use the predefined value. */
  270. #elif U_PLATFORM_USES_ONLY_WIN32_API
  271. # if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600)
  272. /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */
  273. # define U_HAVE_STDINT_H 1
  274. # else
  275. # define U_HAVE_STDINT_H 0
  276. # endif
  277. #elif U_PLATFORM == U_PF_SOLARIS
  278. /* Solaris has inttypes.h but not stdint.h. */
  279. # define U_HAVE_STDINT_H 0
  280. #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
  281. /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
  282. # define U_HAVE_STDINT_H 0
  283. #else
  284. # define U_HAVE_STDINT_H 1
  285. #endif
  286. /**
  287. * \def U_HAVE_INTTYPES_H
  288. * Defines whether inttypes.h is available. It is a C99 standard header.
  289. * We include inttypes.h where it is available but stdint.h is not.
  290. * @internal
  291. */
  292. #ifdef U_HAVE_INTTYPES_H
  293. /* Use the predefined value. */
  294. #elif U_PLATFORM == U_PF_SOLARIS
  295. /* Solaris has inttypes.h but not stdint.h. */
  296. # define U_HAVE_INTTYPES_H 1
  297. #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER)
  298. /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */
  299. # define U_HAVE_INTTYPES_H 1
  300. #else
  301. /* Most platforms have both inttypes.h and stdint.h, or neither. */
  302. # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H
  303. #endif
  304. /**
  305. * \def U_IOSTREAM_SOURCE
  306. * Defines what support for C++ streams is available.
  307. *
  308. * If U_IOSTREAM_SOURCE is set to 199711, then &lt;iostream&gt; is available
  309. * (the ISO/IEC C++ FDIS was published in November 1997), and then
  310. * one should qualify streams using the std namespace in ICU header
  311. * files.
  312. * Starting with ICU 49, this is the only supported version.
  313. *
  314. * If U_IOSTREAM_SOURCE is set to 198506, then &lt;iostream.h&gt; is
  315. * available instead (in June 1985 Stroustrup published
  316. * "An Extensible I/O Facility for C++" at the summer USENIX conference).
  317. * Starting with ICU 49, this version is not supported any more.
  318. *
  319. * If U_IOSTREAM_SOURCE is 0 (or any value less than 199711),
  320. * then C++ streams are not available and
  321. * support for them will be silently suppressed in ICU.
  322. *
  323. * @internal
  324. */
  325. #ifndef U_IOSTREAM_SOURCE
  326. #define U_IOSTREAM_SOURCE 199711
  327. #endif
  328. /**
  329. * \def U_HAVE_STD_STRING
  330. * Defines whether the standard C++ (STL) &lt;string&gt; header is available.
  331. * @internal
  332. */
  333. #ifdef U_HAVE_STD_STRING
  334. /* Use the predefined value. */
  335. #else
  336. # define U_HAVE_STD_STRING 1
  337. #endif
  338. /*===========================================================================*/
  339. /** @{ Compiler and environment features */
  340. /*===========================================================================*/
  341. /**
  342. * \def U_GCC_MAJOR_MINOR
  343. * Indicates whether the compiler is gcc (test for != 0),
  344. * and if so, contains its major (times 100) and minor version numbers.
  345. * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0.
  346. *
  347. * For example, for testing for whether we have gcc, and whether it's 4.6 or higher,
  348. * use "#if U_GCC_MAJOR_MINOR >= 406".
  349. * @internal
  350. */
  351. #ifdef __GNUC__
  352. # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
  353. #else
  354. # define U_GCC_MAJOR_MINOR 0
  355. #endif
  356. /**
  357. * \def U_IS_BIG_ENDIAN
  358. * Determines the endianness of the platform.
  359. * @internal
  360. */
  361. #ifdef U_IS_BIG_ENDIAN
  362. /* Use the predefined value. */
  363. #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
  364. # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
  365. #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
  366. /* gcc */
  367. # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  368. #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
  369. # define U_IS_BIG_ENDIAN 1
  370. #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
  371. # define U_IS_BIG_ENDIAN 0
  372. #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
  373. /* These platforms do not appear to predefine any endianness macros. */
  374. # define U_IS_BIG_ENDIAN 1
  375. #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
  376. /* HPPA do not appear to predefine any endianness macros. */
  377. # define U_IS_BIG_ENDIAN 1
  378. #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
  379. /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
  380. # define U_IS_BIG_ENDIAN 1
  381. #else
  382. # define U_IS_BIG_ENDIAN 0
  383. #endif
  384. /**
  385. * \def U_HAVE_PLACEMENT_NEW
  386. * Determines whether to override placement new and delete for STL.
  387. * @stable ICU 2.6
  388. */
  389. #ifdef U_HAVE_PLACEMENT_NEW
  390. /* Use the predefined value. */
  391. #elif defined(__BORLANDC__)
  392. # define U_HAVE_PLACEMENT_NEW 0
  393. #else
  394. # define U_HAVE_PLACEMENT_NEW 1
  395. #endif
  396. /**
  397. * \def U_HAVE_DEBUG_LOCATION_NEW
  398. * Define this to define the MFC debug version of the operator new.
  399. *
  400. * @stable ICU 3.4
  401. */
  402. #ifdef U_HAVE_DEBUG_LOCATION_NEW
  403. /* Use the predefined value. */
  404. #elif defined(_MSC_VER)
  405. # define U_HAVE_DEBUG_LOCATION_NEW 1
  406. #else
  407. # define U_HAVE_DEBUG_LOCATION_NEW 0
  408. #endif
  409. /* Compatibility with non clang compilers: http://clang.llvm.org/docs/LanguageExtensions.html */
  410. #ifndef __has_attribute
  411. # define __has_attribute(x) 0
  412. #endif
  413. #ifndef __has_cpp_attribute
  414. # define __has_cpp_attribute(x) 0
  415. #endif
  416. #ifndef __has_builtin
  417. # define __has_builtin(x) 0
  418. #endif
  419. #ifndef __has_feature
  420. # define __has_feature(x) 0
  421. #endif
  422. #ifndef __has_extension
  423. # define __has_extension(x) 0
  424. #endif
  425. #ifndef __has_warning
  426. # define __has_warning(x) 0
  427. #endif
  428. /**
  429. * \def U_MALLOC_ATTR
  430. * Attribute to mark functions as malloc-like
  431. * @internal
  432. */
  433. #if defined(__GNUC__) && __GNUC__>=3
  434. # define U_MALLOC_ATTR __attribute__ ((__malloc__))
  435. #else
  436. # define U_MALLOC_ATTR
  437. #endif
  438. /**
  439. * \def U_ALLOC_SIZE_ATTR
  440. * Attribute to specify the size of the allocated buffer for malloc-like functions
  441. * @internal
  442. */
  443. #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size)
  444. # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
  445. # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
  446. #else
  447. # define U_ALLOC_SIZE_ATTR(X)
  448. # define U_ALLOC_SIZE_ATTR2(X,Y)
  449. #endif
  450. /**
  451. * \def U_CPLUSPLUS_VERSION
  452. * 0 if no C++; 1, 11, 14, ... if C++.
  453. * Support for specific features cannot always be determined by the C++ version alone.
  454. * @internal
  455. */
  456. #ifdef U_CPLUSPLUS_VERSION
  457. # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
  458. # undef U_CPLUSPLUS_VERSION
  459. # define U_CPLUSPLUS_VERSION 0
  460. # endif
  461. /* Otherwise use the predefined value. */
  462. #elif !defined(__cplusplus)
  463. # define U_CPLUSPLUS_VERSION 0
  464. #elif __cplusplus >= 201402L
  465. # define U_CPLUSPLUS_VERSION 14
  466. #elif __cplusplus >= 201103L
  467. # define U_CPLUSPLUS_VERSION 11
  468. #else
  469. // C++98 or C++03
  470. # define U_CPLUSPLUS_VERSION 1
  471. #endif
  472. /**
  473. * \def U_HAVE_RVALUE_REFERENCES
  474. * Set to 1 if the compiler supports rvalue references.
  475. * C++11 feature, necessary for move constructor & move assignment.
  476. * @internal
  477. */
  478. #ifdef U_HAVE_RVALUE_REFERENCES
  479. /* Use the predefined value. */
  480. #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_rvalue_references) \
  481. || defined(__GXX_EXPERIMENTAL_CXX0X__) \
  482. || (defined(_MSC_VER) && _MSC_VER >= 1600) /* Visual Studio 2010 */
  483. # define U_HAVE_RVALUE_REFERENCES 1
  484. #else
  485. # define U_HAVE_RVALUE_REFERENCES 0
  486. #endif
  487. /**
  488. * \def U_NOEXCEPT
  489. * "noexcept" if supported, otherwise empty.
  490. * Some code, especially STL containers, uses move semantics of objects only
  491. * if the move constructor and the move operator are declared as not throwing exceptions.
  492. * @internal
  493. */
  494. #ifdef U_NOEXCEPT
  495. /* Use the predefined value. */
  496. #elif defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS /* Visual Studio */
  497. # define U_NOEXCEPT
  498. #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_noexcept) || __has_extension(cxx_noexcept) \
  499. || (defined(_MSC_VER) && _MSC_VER >= 1900) /* Visual Studio 2015 */
  500. # define U_NOEXCEPT noexcept
  501. #else
  502. # define U_NOEXCEPT
  503. #endif
  504. /**
  505. * \def U_FALLTHROUGH
  506. * Annotate intentional fall-through between switch labels.
  507. * http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
  508. * @internal
  509. */
  510. #ifdef __cplusplus
  511. # if __has_cpp_attribute(clang::fallthrough) || \
  512. (__has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough"))
  513. # define U_FALLTHROUGH [[clang::fallthrough]]
  514. # else
  515. # define U_FALLTHROUGH
  516. # endif
  517. #else
  518. # define U_FALLTHROUGH
  519. #endif
  520. /** @} */
  521. /*===========================================================================*/
  522. /** @{ Character data types */
  523. /*===========================================================================*/
  524. /**
  525. * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform.
  526. * @stable ICU 2.0
  527. */
  528. #define U_ASCII_FAMILY 0
  529. /**
  530. * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform.
  531. * @stable ICU 2.0
  532. */
  533. #define U_EBCDIC_FAMILY 1
  534. /**
  535. * \def U_CHARSET_FAMILY
  536. *
  537. * <p>These definitions allow to specify the encoding of text
  538. * in the char data type as defined by the platform and the compiler.
  539. * It is enough to determine the code point values of "invariant characters",
  540. * which are the ones shared by all encodings that are in use
  541. * on a given platform.</p>
  542. *
  543. * <p>Those "invariant characters" should be all the uppercase and lowercase
  544. * latin letters, the digits, the space, and "basic punctuation".
  545. * Also, '\\n', '\\r', '\\t' should be available.</p>
  546. *
  547. * <p>The list of "invariant characters" is:<br>
  548. * \code
  549. * A-Z a-z 0-9 SPACE " % &amp; ' ( ) * + , - . / : ; < = > ? _
  550. * \endcode
  551. * <br>
  552. * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p>
  553. *
  554. * <p>This matches the IBM Syntactic Character Set (CS 640).</p>
  555. *
  556. * <p>In other words, all the graphic characters in 7-bit ASCII should
  557. * be safely accessible except the following:</p>
  558. *
  559. * \code
  560. * '\' <backslash>
  561. * '[' <left bracket>
  562. * ']' <right bracket>
  563. * '{' <left brace>
  564. * '}' <right brace>
  565. * '^' <circumflex>
  566. * '~' <tilde>
  567. * '!' <exclamation mark>
  568. * '#' <number sign>
  569. * '|' <vertical line>
  570. * '$' <dollar sign>
  571. * '@' <commercial at>
  572. * '`' <grave accent>
  573. * \endcode
  574. * @stable ICU 2.0
  575. */
  576. #ifdef U_CHARSET_FAMILY
  577. /* Use the predefined value. */
  578. #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
  579. # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
  580. #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
  581. # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
  582. #else
  583. # define U_CHARSET_FAMILY U_ASCII_FAMILY
  584. #endif
  585. /**
  586. * \def U_CHARSET_IS_UTF8
  587. *
  588. * Hardcode the default charset to UTF-8.
  589. *
  590. * If this is set to 1, then
  591. * - ICU will assume that all non-invariant char*, StringPiece, std::string etc.
  592. * contain UTF-8 text, regardless of what the system API uses
  593. * - some ICU code will use fast functions like u_strFromUTF8()
  594. * rather than the more general and more heavy-weight conversion API (ucnv.h)
  595. * - ucnv_getDefaultName() always returns "UTF-8"
  596. * - ucnv_setDefaultName() is disabled and will not change the default charset
  597. * - static builds of ICU are smaller
  598. * - more functionality is available with the UCONFIG_NO_CONVERSION build-time
  599. * configuration option (see unicode/uconfig.h)
  600. * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable
  601. *
  602. * @stable ICU 4.2
  603. * @see UCONFIG_NO_CONVERSION
  604. */
  605. #ifdef U_CHARSET_IS_UTF8
  606. /* Use the predefined value. */
  607. #elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED
  608. # define U_CHARSET_IS_UTF8 1
  609. #else
  610. # define U_CHARSET_IS_UTF8 0
  611. #endif
  612. /** @} */
  613. /*===========================================================================*/
  614. /** @{ Information about wchar support */
  615. /*===========================================================================*/
  616. /**
  617. * \def U_HAVE_WCHAR_H
  618. * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
  619. *
  620. * @stable ICU 2.0
  621. */
  622. #ifdef U_HAVE_WCHAR_H
  623. /* Use the predefined value. */
  624. #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
  625. /*
  626. * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
  627. * The type and header existed, but the library functions did not work as expected.
  628. * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
  629. */
  630. # define U_HAVE_WCHAR_H 0
  631. #else
  632. # define U_HAVE_WCHAR_H 1
  633. #endif
  634. /**
  635. * \def U_SIZEOF_WCHAR_T
  636. * U_SIZEOF_WCHAR_T==sizeof(wchar_t)
  637. *
  638. * @stable ICU 2.0
  639. */
  640. #ifdef U_SIZEOF_WCHAR_T
  641. /* Use the predefined value. */
  642. #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
  643. /*
  644. * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
  645. * Newer Mac OS X has size 4.
  646. */
  647. # define U_SIZEOF_WCHAR_T 1
  648. #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
  649. # define U_SIZEOF_WCHAR_T 2
  650. #elif U_PLATFORM == U_PF_AIX
  651. /*
  652. * AIX 6.1 information, section "Wide character data representation":
  653. * "... the wchar_t datatype is 32-bit in the 64-bit environment and
  654. * 16-bit in the 32-bit environment."
  655. * and
  656. * "All locales use Unicode for their wide character code values (process code),
  657. * except the IBM-eucTW codeset."
  658. */
  659. # ifdef __64BIT__
  660. # define U_SIZEOF_WCHAR_T 4
  661. # else
  662. # define U_SIZEOF_WCHAR_T 2
  663. # endif
  664. #elif U_PLATFORM == U_PF_OS390
  665. /*
  666. * z/OS V1R11 information center, section "LP64 | ILP32":
  667. * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
  668. * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
  669. */
  670. # ifdef _LP64
  671. # define U_SIZEOF_WCHAR_T 4
  672. # else
  673. # define U_SIZEOF_WCHAR_T 2
  674. # endif
  675. #elif U_PLATFORM == U_PF_OS400
  676. # if defined(__UTF32__)
  677. /*
  678. * LOCALETYPE(*LOCALEUTF) is specified.
  679. * Wide-character strings are in UTF-32,
  680. * narrow-character strings are in UTF-8.
  681. */
  682. # define U_SIZEOF_WCHAR_T 4
  683. # elif defined(__UCS2__)
  684. /*
  685. * LOCALETYPE(*LOCALEUCS2) is specified.
  686. * Wide-character strings are in UCS-2,
  687. * narrow-character strings are in EBCDIC.
  688. */
  689. # define U_SIZEOF_WCHAR_T 2
  690. #else
  691. /*
  692. * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
  693. * Wide-character strings are in 16-bit EBCDIC,
  694. * narrow-character strings are in EBCDIC.
  695. */
  696. # define U_SIZEOF_WCHAR_T 2
  697. # endif
  698. #else
  699. # define U_SIZEOF_WCHAR_T 4
  700. #endif
  701. #ifndef U_HAVE_WCSCPY
  702. #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
  703. #endif
  704. /** @} */
  705. /**
  706. * \def U_HAVE_CHAR16_T
  707. * Defines whether the char16_t type is available for UTF-16
  708. * and u"abc" UTF-16 string literals are supported.
  709. * This is a new standard type and standard string literal syntax in C++0x
  710. * but has been available in some compilers before.
  711. * @internal
  712. */
  713. #ifdef U_HAVE_CHAR16_T
  714. /* Use the predefined value. */
  715. #else
  716. /*
  717. * Notes:
  718. * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but
  719. * does not support u"abc" string literals.
  720. * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but
  721. * does not support u"abc" string literals.
  722. * C++11 and C11 require support for UTF-16 literals
  723. */
  724. # if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
  725. # define U_HAVE_CHAR16_T 1
  726. # else
  727. # define U_HAVE_CHAR16_T 0
  728. # endif
  729. #endif
  730. /**
  731. * @{
  732. * \def U_DECLARE_UTF16
  733. * Do not use this macro because it is not defined on all platforms.
  734. * Use the UNICODE_STRING or U_STRING_DECL macros instead.
  735. * @internal
  736. */
  737. #ifdef U_DECLARE_UTF16
  738. /* Use the predefined value. */
  739. #elif U_HAVE_CHAR16_T \
  740. || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
  741. || (defined(__HP_aCC) && __HP_aCC >= 035000) \
  742. || (defined(__HP_cc) && __HP_cc >= 111106)
  743. # define U_DECLARE_UTF16(string) u ## string
  744. #elif U_SIZEOF_WCHAR_T == 2 \
  745. && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
  746. # define U_DECLARE_UTF16(string) L ## string
  747. #else
  748. /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
  749. #endif
  750. /** @} */
  751. /*===========================================================================*/
  752. /** @{ Symbol import-export control */
  753. /*===========================================================================*/
  754. #ifdef U_EXPORT
  755. /* Use the predefined value. */
  756. #elif defined(U_STATIC_IMPLEMENTATION)
  757. # define U_EXPORT
  758. #elif defined(__GNUC__)
  759. # define U_EXPORT __attribute__((visibility("default")))
  760. #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
  761. || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
  762. # define U_EXPORT __global
  763. /*#elif defined(__HP_aCC) || defined(__HP_cc)
  764. # define U_EXPORT __declspec(dllexport)*/
  765. #elif defined(_MSC_VER)
  766. # define U_EXPORT __declspec(dllexport)
  767. #else
  768. # define U_EXPORT
  769. #endif
  770. /* U_CALLCONV is releated to U_EXPORT2 */
  771. #ifdef U_EXPORT2
  772. /* Use the predefined value. */
  773. #elif defined(_MSC_VER)
  774. # define U_EXPORT2 __cdecl
  775. #else
  776. # define U_EXPORT2
  777. #endif
  778. #ifdef U_IMPORT
  779. /* Use the predefined value. */
  780. #elif defined(_MSC_VER)
  781. /* Windows needs to export/import data. */
  782. # define U_IMPORT __declspec(dllimport)
  783. #else
  784. # define U_IMPORT
  785. #endif
  786. /**
  787. * \def U_CALLCONV
  788. * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary
  789. * in callback function typedefs to make sure that the calling convention
  790. * is compatible.
  791. *
  792. * This is only used for non-ICU-API functions.
  793. * When a function is a public ICU API,
  794. * you must use the U_CAPI and U_EXPORT2 qualifiers.
  795. *
  796. * Please note, you need to use U_CALLCONV after the *.
  797. *
  798. * NO : "static const char U_CALLCONV *func( . . . )"
  799. * YES: "static const char* U_CALLCONV func( . . . )"
  800. *
  801. * @stable ICU 2.0
  802. */
  803. #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
  804. # define U_CALLCONV __cdecl
  805. #else
  806. # define U_CALLCONV U_EXPORT2
  807. #endif
  808. /* @} */
  809. #endif