platform.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. // © 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 \#define 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. /** Fuchsia is a POSIX-ish platform. @internal */
  129. #define U_PF_FUCHSIA 4100
  130. /* Maximum value for Linux-based platform is 4499 */
  131. /**
  132. * Emscripten is a C++ transpiler for the Web that can target asm.js or
  133. * WebAssembly. It provides some POSIX-compatible wrappers and stubs and
  134. * some Linux-like functionality, but is not fully compatible with
  135. * either.
  136. * @internal
  137. */
  138. #define U_PF_EMSCRIPTEN 5010
  139. /** z/OS is the successor to OS/390 which was the successor to MVS. @internal */
  140. #define U_PF_OS390 9000
  141. /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */
  142. #define U_PF_OS400 9400
  143. #ifdef U_PLATFORM
  144. /* Use the predefined value. */
  145. #elif defined(__MINGW32__)
  146. # define U_PLATFORM U_PF_MINGW
  147. #elif defined(__CYGWIN__)
  148. # define U_PLATFORM U_PF_CYGWIN
  149. #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
  150. # define U_PLATFORM U_PF_WINDOWS
  151. #elif defined(__ANDROID__)
  152. # define U_PLATFORM U_PF_ANDROID
  153. /* Android wchar_t support depends on the API level. */
  154. # include <android/api-level.h>
  155. #elif defined(__pnacl__) || defined(__native_client__)
  156. # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
  157. #elif defined(__Fuchsia__)
  158. # define U_PLATFORM U_PF_FUCHSIA
  159. #elif defined(linux) || defined(__linux__) || defined(__linux)
  160. # define U_PLATFORM U_PF_LINUX
  161. #elif defined(__APPLE__) && defined(__MACH__)
  162. # include <TargetConditionals.h>
  163. # if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && (defined(TARGET_OS_MACCATALYST) && !TARGET_OS_MACCATALYST) /* variant of TARGET_OS_MAC */
  164. # define U_PLATFORM U_PF_IPHONE
  165. # else
  166. # define U_PLATFORM U_PF_DARWIN
  167. # endif
  168. #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
  169. # if defined(__FreeBSD__)
  170. # include <sys/endian.h>
  171. # endif
  172. # define U_PLATFORM U_PF_BSD
  173. #elif defined(sun) || defined(__sun)
  174. /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
  175. # define U_PLATFORM U_PF_SOLARIS
  176. # if defined(__GNUC__)
  177. /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
  178. * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
  179. * is included which does not include this header file.
  180. */
  181. # error #include <sys/isa_defs.h>
  182. # endif
  183. #elif defined(_AIX) || defined(__TOS_AIX__)
  184. # define U_PLATFORM U_PF_AIX
  185. #elif defined(_hpux) || defined(hpux) || defined(__hpux)
  186. # define U_PLATFORM U_PF_HPUX
  187. #elif defined(sgi) || defined(__sgi)
  188. # define U_PLATFORM U_PF_IRIX
  189. #elif defined(__QNX__) || defined(__QNXNTO__)
  190. # define U_PLATFORM U_PF_QNX
  191. #elif defined(__TOS_MVS__)
  192. # define U_PLATFORM U_PF_OS390
  193. #elif defined(__OS400__) || defined(__TOS_OS400__)
  194. # define U_PLATFORM U_PF_OS400
  195. #elif defined(__EMSCRIPTEN__)
  196. # define U_PLATFORM U_PF_EMSCRIPTEN
  197. #else
  198. # define U_PLATFORM U_PF_UNKNOWN
  199. #endif
  200. /**
  201. * \def U_REAL_MSVC
  202. * Defined if the compiler is the real MSVC compiler (and not something like
  203. * Clang setting _MSC_VER in order to compile Windows code that requires it).
  204. * Otherwise undefined.
  205. * @internal
  206. */
  207. #if (defined(_MSC_VER) && !(defined(__clang__) && __clang__)) || defined(U_IN_DOXYGEN)
  208. # define U_REAL_MSVC
  209. #endif
  210. /**
  211. * \def CYGWINMSVC
  212. * Defined if this is Windows with Cygwin, but using MSVC rather than gcc.
  213. * Otherwise undefined.
  214. * @internal
  215. */
  216. /* Commented out because this is already set in mh-cygwin-msvc
  217. #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
  218. # define CYGWINMSVC
  219. #endif
  220. */
  221. #ifdef U_IN_DOXYGEN
  222. # define CYGWINMSVC
  223. #endif
  224. /**
  225. * \def U_PLATFORM_USES_ONLY_WIN32_API
  226. * Defines whether the platform uses only the Win32 API.
  227. * Set to 1 for Windows/MSVC and MinGW but not Cygwin.
  228. * @internal
  229. */
  230. #ifdef U_PLATFORM_USES_ONLY_WIN32_API
  231. /* Use the predefined value. */
  232. #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
  233. # define U_PLATFORM_USES_ONLY_WIN32_API 1
  234. #else
  235. /* Cygwin implements POSIX. */
  236. # define U_PLATFORM_USES_ONLY_WIN32_API 0
  237. #endif
  238. /**
  239. * \def U_PLATFORM_HAS_WIN32_API
  240. * Defines whether the Win32 API is available on the platform.
  241. * Set to 1 for Windows/MSVC, MinGW and Cygwin.
  242. * @internal
  243. */
  244. #ifdef U_PLATFORM_HAS_WIN32_API
  245. /* Use the predefined value. */
  246. #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  247. # define U_PLATFORM_HAS_WIN32_API 1
  248. #else
  249. # define U_PLATFORM_HAS_WIN32_API 0
  250. #endif
  251. /**
  252. * \def U_PLATFORM_HAS_WINUWP_API
  253. * Defines whether target is intended for Universal Windows Platform API
  254. * Set to 1 for Windows10 Release Solution Configuration
  255. * @internal
  256. */
  257. #ifdef U_PLATFORM_HAS_WINUWP_API
  258. /* Use the predefined value. */
  259. #else
  260. # define U_PLATFORM_HAS_WINUWP_API 0
  261. #endif
  262. /**
  263. * \def U_PLATFORM_IMPLEMENTS_POSIX
  264. * Defines whether the platform implements (most of) the POSIX API.
  265. * Set to 1 for Cygwin and most other platforms.
  266. * @internal
  267. */
  268. #ifdef U_PLATFORM_IMPLEMENTS_POSIX
  269. /* Use the predefined value. */
  270. #elif U_PLATFORM_USES_ONLY_WIN32_API
  271. # define U_PLATFORM_IMPLEMENTS_POSIX 0
  272. #else
  273. # define U_PLATFORM_IMPLEMENTS_POSIX 1
  274. #endif
  275. /**
  276. * \def U_PLATFORM_IS_LINUX_BASED
  277. * Defines whether the platform is Linux or one of its derivatives.
  278. * @internal
  279. */
  280. #ifdef U_PLATFORM_IS_LINUX_BASED
  281. /* Use the predefined value. */
  282. #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
  283. # define U_PLATFORM_IS_LINUX_BASED 1
  284. #else
  285. # define U_PLATFORM_IS_LINUX_BASED 0
  286. #endif
  287. /**
  288. * \def U_PLATFORM_IS_DARWIN_BASED
  289. * Defines whether the platform is Darwin or one of its derivatives.
  290. * @internal
  291. */
  292. #ifdef U_PLATFORM_IS_DARWIN_BASED
  293. /* Use the predefined value. */
  294. #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
  295. # define U_PLATFORM_IS_DARWIN_BASED 1
  296. #else
  297. # define U_PLATFORM_IS_DARWIN_BASED 0
  298. #endif
  299. /*===========================================================================*/
  300. /** @{ Compiler and environment features */
  301. /*===========================================================================*/
  302. /**
  303. * \def U_GCC_MAJOR_MINOR
  304. * Indicates whether the compiler is gcc (test for != 0),
  305. * and if so, contains its major (times 100) and minor version numbers.
  306. * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0.
  307. *
  308. * For example, for testing for whether we have gcc, and whether it's 4.6 or higher,
  309. * use "#if U_GCC_MAJOR_MINOR >= 406".
  310. * @internal
  311. */
  312. #ifdef __GNUC__
  313. # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
  314. #else
  315. # define U_GCC_MAJOR_MINOR 0
  316. #endif
  317. /**
  318. * \def U_IS_BIG_ENDIAN
  319. * Determines the endianness of the platform.
  320. * @internal
  321. */
  322. #ifdef U_IS_BIG_ENDIAN
  323. /* Use the predefined value. */
  324. #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
  325. # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
  326. #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
  327. /* gcc */
  328. # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  329. #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
  330. # define U_IS_BIG_ENDIAN 1
  331. #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
  332. # define U_IS_BIG_ENDIAN 0
  333. #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
  334. /* These platforms do not appear to predefine any endianness macros. */
  335. # define U_IS_BIG_ENDIAN 1
  336. #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
  337. /* HPPA do not appear to predefine any endianness macros. */
  338. # define U_IS_BIG_ENDIAN 1
  339. #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
  340. /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
  341. # define U_IS_BIG_ENDIAN 1
  342. #else
  343. # define U_IS_BIG_ENDIAN 0
  344. #endif
  345. /**
  346. * \def U_HAVE_PLACEMENT_NEW
  347. * Determines whether to override placement new and delete for STL.
  348. * @stable ICU 2.6
  349. */
  350. #ifdef U_HAVE_PLACEMENT_NEW
  351. /* Use the predefined value. */
  352. #elif defined(__BORLANDC__)
  353. # define U_HAVE_PLACEMENT_NEW 0
  354. #else
  355. # define U_HAVE_PLACEMENT_NEW 1
  356. #endif
  357. /**
  358. * \def U_HAVE_DEBUG_LOCATION_NEW
  359. * Define this to define the MFC debug version of the operator new.
  360. *
  361. * @stable ICU 3.4
  362. */
  363. #ifdef U_HAVE_DEBUG_LOCATION_NEW
  364. /* Use the predefined value. */
  365. #elif defined(_MSC_VER)
  366. # define U_HAVE_DEBUG_LOCATION_NEW 1
  367. #else
  368. # define U_HAVE_DEBUG_LOCATION_NEW 0
  369. #endif
  370. /* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */
  371. #ifdef __has_attribute
  372. # define UPRV_HAS_ATTRIBUTE(x) __has_attribute(x)
  373. #else
  374. # define UPRV_HAS_ATTRIBUTE(x) 0
  375. #endif
  376. #ifdef __has_cpp_attribute
  377. # define UPRV_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
  378. #else
  379. # define UPRV_HAS_CPP_ATTRIBUTE(x) 0
  380. #endif
  381. #ifdef __has_declspec_attribute
  382. # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) __has_declspec_attribute(x)
  383. #else
  384. # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) 0
  385. #endif
  386. #ifdef __has_builtin
  387. # define UPRV_HAS_BUILTIN(x) __has_builtin(x)
  388. #else
  389. # define UPRV_HAS_BUILTIN(x) 0
  390. #endif
  391. #ifdef __has_feature
  392. # define UPRV_HAS_FEATURE(x) __has_feature(x)
  393. #else
  394. # define UPRV_HAS_FEATURE(x) 0
  395. #endif
  396. #ifdef __has_extension
  397. # define UPRV_HAS_EXTENSION(x) __has_extension(x)
  398. #else
  399. # define UPRV_HAS_EXTENSION(x) 0
  400. #endif
  401. #ifdef __has_warning
  402. # define UPRV_HAS_WARNING(x) __has_warning(x)
  403. #else
  404. # define UPRV_HAS_WARNING(x) 0
  405. #endif
  406. #if defined(__clang__)
  407. #define UPRV_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
  408. #else
  409. #define UPRV_NO_SANITIZE_UNDEFINED
  410. #endif
  411. /**
  412. * \def U_MALLOC_ATTR
  413. * Attribute to mark functions as malloc-like
  414. * @internal
  415. */
  416. #if defined(__GNUC__) && __GNUC__>=3
  417. # define U_MALLOC_ATTR __attribute__ ((__malloc__))
  418. #else
  419. # define U_MALLOC_ATTR
  420. #endif
  421. /**
  422. * \def U_ALLOC_SIZE_ATTR
  423. * Attribute to specify the size of the allocated buffer for malloc-like functions
  424. * @internal
  425. */
  426. #if (defined(__GNUC__) && \
  427. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
  428. UPRV_HAS_ATTRIBUTE(alloc_size)
  429. # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
  430. # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
  431. #else
  432. # define U_ALLOC_SIZE_ATTR(X)
  433. # define U_ALLOC_SIZE_ATTR2(X,Y)
  434. #endif
  435. /**
  436. * \def U_CPLUSPLUS_VERSION
  437. * 0 if no C++; 1, 11, 14, ... if C++.
  438. * Support for specific features cannot always be determined by the C++ version alone.
  439. * @internal
  440. */
  441. #ifdef U_CPLUSPLUS_VERSION
  442. # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
  443. # undef U_CPLUSPLUS_VERSION
  444. # define U_CPLUSPLUS_VERSION 0
  445. # endif
  446. /* Otherwise use the predefined value. */
  447. #elif !defined(__cplusplus)
  448. # define U_CPLUSPLUS_VERSION 0
  449. #elif __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
  450. # define U_CPLUSPLUS_VERSION 17
  451. #elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
  452. # define U_CPLUSPLUS_VERSION 14
  453. #elif __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
  454. # define U_CPLUSPLUS_VERSION 11
  455. #else
  456. // C++98 or C++03
  457. # define U_CPLUSPLUS_VERSION 1
  458. #endif
  459. /**
  460. * \def U_FALLTHROUGH
  461. * Annotate intentional fall-through between switch labels.
  462. * http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
  463. * @internal
  464. */
  465. #ifndef __cplusplus
  466. // Not for C.
  467. #elif defined(U_FALLTHROUGH)
  468. // Use the predefined value.
  469. #elif defined(__clang__)
  470. // Test for compiler vs. feature separately.
  471. // Other compilers might choke on the feature test.
  472. # if UPRV_HAS_CPP_ATTRIBUTE(clang::fallthrough) || \
  473. (UPRV_HAS_FEATURE(cxx_attributes) && \
  474. UPRV_HAS_WARNING("-Wimplicit-fallthrough"))
  475. # define U_FALLTHROUGH [[clang::fallthrough]]
  476. # endif
  477. #elif defined(__GNUC__) && (__GNUC__ >= 7)
  478. # define U_FALLTHROUGH __attribute__((fallthrough))
  479. #endif
  480. #ifndef U_FALLTHROUGH
  481. # define U_FALLTHROUGH
  482. #endif
  483. /** @} */
  484. /*===========================================================================*/
  485. /** @{ Character data types */
  486. /*===========================================================================*/
  487. /**
  488. * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform.
  489. * @stable ICU 2.0
  490. */
  491. #define U_ASCII_FAMILY 0
  492. /**
  493. * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform.
  494. * @stable ICU 2.0
  495. */
  496. #define U_EBCDIC_FAMILY 1
  497. /**
  498. * \def U_CHARSET_FAMILY
  499. *
  500. * <p>These definitions allow to specify the encoding of text
  501. * in the char data type as defined by the platform and the compiler.
  502. * It is enough to determine the code point values of "invariant characters",
  503. * which are the ones shared by all encodings that are in use
  504. * on a given platform.</p>
  505. *
  506. * <p>Those "invariant characters" should be all the uppercase and lowercase
  507. * latin letters, the digits, the space, and "basic punctuation".
  508. * Also, '\\n', '\\r', '\\t' should be available.</p>
  509. *
  510. * <p>The list of "invariant characters" is:<br>
  511. * \code
  512. * A-Z a-z 0-9 SPACE " % &amp; ' ( ) * + , - . / : ; < = > ? _
  513. * \endcode
  514. * <br>
  515. * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p>
  516. *
  517. * <p>This matches the IBM Syntactic Character Set (CS 640).</p>
  518. *
  519. * <p>In other words, all the graphic characters in 7-bit ASCII should
  520. * be safely accessible except the following:</p>
  521. *
  522. * \code
  523. * '\' <backslash>
  524. * '[' <left bracket>
  525. * ']' <right bracket>
  526. * '{' <left brace>
  527. * '}' <right brace>
  528. * '^' <circumflex>
  529. * '~' <tilde>
  530. * '!' <exclamation mark>
  531. * '#' <number sign>
  532. * '|' <vertical line>
  533. * '$' <dollar sign>
  534. * '@' <commercial at>
  535. * '`' <grave accent>
  536. * \endcode
  537. * @stable ICU 2.0
  538. */
  539. #ifdef U_CHARSET_FAMILY
  540. /* Use the predefined value. */
  541. #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
  542. # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
  543. #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
  544. # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
  545. #else
  546. # define U_CHARSET_FAMILY U_ASCII_FAMILY
  547. #endif
  548. /**
  549. * \def U_CHARSET_IS_UTF8
  550. *
  551. * Hardcode the default charset to UTF-8.
  552. *
  553. * If this is set to 1, then
  554. * - ICU will assume that all non-invariant char*, StringPiece, std::string etc.
  555. * contain UTF-8 text, regardless of what the system API uses
  556. * - some ICU code will use fast functions like u_strFromUTF8()
  557. * rather than the more general and more heavy-weight conversion API (ucnv.h)
  558. * - ucnv_getDefaultName() always returns "UTF-8"
  559. * - ucnv_setDefaultName() is disabled and will not change the default charset
  560. * - static builds of ICU are smaller
  561. * - more functionality is available with the UCONFIG_NO_CONVERSION build-time
  562. * configuration option (see unicode/uconfig.h)
  563. * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable
  564. *
  565. * @stable ICU 4.2
  566. * @see UCONFIG_NO_CONVERSION
  567. */
  568. #ifdef U_CHARSET_IS_UTF8
  569. /* Use the predefined value. */
  570. #elif U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED || \
  571. U_PLATFORM == U_PF_EMSCRIPTEN
  572. # define U_CHARSET_IS_UTF8 1
  573. #else
  574. # define U_CHARSET_IS_UTF8 0
  575. #endif
  576. /** @} */
  577. /*===========================================================================*/
  578. /** @{ Information about wchar support */
  579. /*===========================================================================*/
  580. /**
  581. * \def U_HAVE_WCHAR_H
  582. * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default.
  583. *
  584. * @stable ICU 2.0
  585. */
  586. #ifdef U_HAVE_WCHAR_H
  587. /* Use the predefined value. */
  588. #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
  589. /*
  590. * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
  591. * The type and header existed, but the library functions did not work as expected.
  592. * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
  593. */
  594. # define U_HAVE_WCHAR_H 0
  595. #else
  596. # define U_HAVE_WCHAR_H 1
  597. #endif
  598. /**
  599. * \def U_SIZEOF_WCHAR_T
  600. * U_SIZEOF_WCHAR_T==sizeof(wchar_t)
  601. *
  602. * @stable ICU 2.0
  603. */
  604. #ifdef U_SIZEOF_WCHAR_T
  605. /* Use the predefined value. */
  606. #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
  607. /*
  608. * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
  609. * Newer Mac OS X has size 4.
  610. */
  611. # define U_SIZEOF_WCHAR_T 1
  612. #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
  613. # define U_SIZEOF_WCHAR_T 2
  614. #elif U_PLATFORM == U_PF_AIX
  615. /*
  616. * AIX 6.1 information, section "Wide character data representation":
  617. * "... the wchar_t datatype is 32-bit in the 64-bit environment and
  618. * 16-bit in the 32-bit environment."
  619. * and
  620. * "All locales use Unicode for their wide character code values (process code),
  621. * except the IBM-eucTW codeset."
  622. */
  623. # ifdef __64BIT__
  624. # define U_SIZEOF_WCHAR_T 4
  625. # else
  626. # define U_SIZEOF_WCHAR_T 2
  627. # endif
  628. #elif U_PLATFORM == U_PF_OS390
  629. /*
  630. * z/OS V1R11 information center, section "LP64 | ILP32":
  631. * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
  632. * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
  633. */
  634. # ifdef _LP64
  635. # define U_SIZEOF_WCHAR_T 4
  636. # else
  637. # define U_SIZEOF_WCHAR_T 2
  638. # endif
  639. #elif U_PLATFORM == U_PF_OS400
  640. # if defined(__UTF32__)
  641. /*
  642. * LOCALETYPE(*LOCALEUTF) is specified.
  643. * Wide-character strings are in UTF-32,
  644. * narrow-character strings are in UTF-8.
  645. */
  646. # define U_SIZEOF_WCHAR_T 4
  647. # elif defined(__UCS2__)
  648. /*
  649. * LOCALETYPE(*LOCALEUCS2) is specified.
  650. * Wide-character strings are in UCS-2,
  651. * narrow-character strings are in EBCDIC.
  652. */
  653. # define U_SIZEOF_WCHAR_T 2
  654. # else
  655. /*
  656. * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
  657. * Wide-character strings are in 16-bit EBCDIC,
  658. * narrow-character strings are in EBCDIC.
  659. */
  660. # define U_SIZEOF_WCHAR_T 2
  661. # endif
  662. #else
  663. # define U_SIZEOF_WCHAR_T 4
  664. #endif
  665. #ifndef U_HAVE_WCSCPY
  666. #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
  667. #endif
  668. /** @} */
  669. /**
  670. * \def U_HAVE_CHAR16_T
  671. * Defines whether the char16_t type is available for UTF-16
  672. * and u"abc" UTF-16 string literals are supported.
  673. * This is a new standard type and standard string literal syntax in C++11
  674. * but has been available in some compilers before.
  675. * @internal
  676. */
  677. #ifdef U_HAVE_CHAR16_T
  678. /* Use the predefined value. */
  679. #else
  680. /*
  681. * Notes:
  682. * C++11 and C11 require support for UTF-16 literals
  683. * Doesn't work on Mac C11 (see workaround in ptypes.h).
  684. */
  685. # if defined(__cplusplus) || !U_PLATFORM_IS_DARWIN_BASED
  686. # define U_HAVE_CHAR16_T 1
  687. # else
  688. # define U_HAVE_CHAR16_T 0
  689. # endif
  690. #endif
  691. /**
  692. * @{
  693. * \def U_DECLARE_UTF16
  694. * Do not use this macro because it is not defined on all platforms.
  695. * Use the UNICODE_STRING or U_STRING_DECL macros instead.
  696. * @internal
  697. */
  698. #ifdef U_DECLARE_UTF16
  699. /* Use the predefined value. */
  700. #elif U_HAVE_CHAR16_T \
  701. || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
  702. || (defined(__HP_aCC) && __HP_aCC >= 035000) \
  703. || (defined(__HP_cc) && __HP_cc >= 111106) \
  704. || (defined(U_IN_DOXYGEN))
  705. # define U_DECLARE_UTF16(string) u ## string
  706. #elif U_SIZEOF_WCHAR_T == 2 \
  707. && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
  708. # define U_DECLARE_UTF16(string) L ## string
  709. #else
  710. /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
  711. #endif
  712. /** @} */
  713. /*===========================================================================*/
  714. /** @{ Symbol import-export control */
  715. /*===========================================================================*/
  716. #ifdef U_EXPORT
  717. /* Use the predefined value. */
  718. #elif defined(U_STATIC_IMPLEMENTATION)
  719. # define U_EXPORT
  720. #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
  721. UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
  722. # define U_EXPORT __declspec(dllexport)
  723. #elif defined(__GNUC__)
  724. # define U_EXPORT __attribute__((visibility("default")))
  725. #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
  726. || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
  727. # define U_EXPORT __global
  728. /*#elif defined(__HP_aCC) || defined(__HP_cc)
  729. # define U_EXPORT __declspec(dllexport)*/
  730. #else
  731. # define U_EXPORT
  732. #endif
  733. /* U_CALLCONV is related to U_EXPORT2 */
  734. #ifdef U_EXPORT2
  735. /* Use the predefined value. */
  736. #elif defined(_MSC_VER)
  737. # define U_EXPORT2 __cdecl
  738. #else
  739. # define U_EXPORT2
  740. #endif
  741. #ifdef U_IMPORT
  742. /* Use the predefined value. */
  743. #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
  744. UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
  745. /* Windows needs to export/import data. */
  746. # define U_IMPORT __declspec(dllimport)
  747. #else
  748. # define U_IMPORT
  749. #endif
  750. /**
  751. * \def U_HIDDEN
  752. * This is used to mark internal structs declared within external classes,
  753. * to prevent the internal structs from having the same visibility as the
  754. * class within which they are declared.
  755. * @internal
  756. */
  757. #ifdef U_HIDDEN
  758. /* Use the predefined value. */
  759. #elif defined(__GNUC__)
  760. # define U_HIDDEN __attribute__((visibility("hidden")))
  761. #else
  762. # define U_HIDDEN
  763. #endif
  764. /**
  765. * \def U_CALLCONV
  766. * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary
  767. * in callback function typedefs to make sure that the calling convention
  768. * is compatible.
  769. *
  770. * This is only used for non-ICU-API functions.
  771. * When a function is a public ICU API,
  772. * you must use the U_CAPI and U_EXPORT2 qualifiers.
  773. *
  774. * Please note, you need to use U_CALLCONV after the *.
  775. *
  776. * NO : "static const char U_CALLCONV *func( . . . )"
  777. * YES: "static const char* U_CALLCONV func( . . . )"
  778. *
  779. * @stable ICU 2.0
  780. */
  781. #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
  782. # define U_CALLCONV __cdecl
  783. #else
  784. # define U_CALLCONV U_EXPORT2
  785. #endif
  786. /**
  787. * \def U_CALLCONV_FPTR
  788. * Similar to U_CALLCONV, but only used on function pointers.
  789. * @internal
  790. */
  791. #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
  792. # define U_CALLCONV_FPTR U_CALLCONV
  793. #else
  794. # define U_CALLCONV_FPTR
  795. #endif
  796. /** @} */
  797. #endif // _PLATFORM_H