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