ICU 75.1  75.1
platform.h
Go to the documentation of this file.
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 #include "unicode/uvernum.h"
26 
59 #ifdef U_IN_DOXYGEN
60 /*
61  * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented.
62  * 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.
63  */
64 
65 /* None for now. */
66 #endif
67 
89 #define U_PF_UNKNOWN 0
91 #define U_PF_WINDOWS 1000
93 #define U_PF_MINGW 1800
99 #define U_PF_CYGWIN 1900
100 /* Reserve 2000 for U_PF_UNIX? */
102 #define U_PF_HPUX 2100
104 #define U_PF_SOLARIS 2600
106 #define U_PF_BSD 3000
108 #define U_PF_AIX 3100
110 #define U_PF_IRIX 3200
119 #define U_PF_DARWIN 3500
121 #define U_PF_IPHONE 3550
123 #define U_PF_QNX 3700
125 #define U_PF_LINUX 4000
132 #define U_PF_BROWSER_NATIVE_CLIENT 4020
134 #define U_PF_ANDROID 4050
136 #define U_PF_FUCHSIA 4100
137 /* Maximum value for Linux-based platform is 4499 */
145 #define U_PF_EMSCRIPTEN 5010
147 #define U_PF_OS390 9000
149 #define U_PF_OS400 9400
150 
151 #ifdef U_PLATFORM
152  /* Use the predefined value. */
153 #elif defined(__MINGW32__)
154 # define U_PLATFORM U_PF_MINGW
155 #elif defined(__CYGWIN__)
156 # define U_PLATFORM U_PF_CYGWIN
157 #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
158 # define U_PLATFORM U_PF_WINDOWS
159 #elif defined(__ANDROID__)
160 # define U_PLATFORM U_PF_ANDROID
161  /* Android wchar_t support depends on the API level. */
162 # include <android/api-level.h>
163 #elif defined(__pnacl__) || defined(__native_client__)
164 # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT
165 #elif defined(__Fuchsia__)
166 # define U_PLATFORM U_PF_FUCHSIA
167 #elif defined(linux) || defined(__linux__) || defined(__linux)
168 # define U_PLATFORM U_PF_LINUX
169 #elif defined(__APPLE__) && defined(__MACH__)
170 # include <TargetConditionals.h>
171 # if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && (defined(TARGET_OS_MACCATALYST) && !TARGET_OS_MACCATALYST) /* variant of TARGET_OS_MAC */
172 # define U_PLATFORM U_PF_IPHONE
173 # else
174 # define U_PLATFORM U_PF_DARWIN
175 # endif
176 #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__)
177 # if defined(__FreeBSD__)
178 # include <sys/endian.h>
179 # endif
180 # define U_PLATFORM U_PF_BSD
181 #elif defined(sun) || defined(__sun)
182  /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */
183 # define U_PLATFORM U_PF_SOLARIS
184 # if defined(__GNUC__)
185  /* Solaris/GCC needs this header file to get the proper endianness. Normally, this
186  * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h
187  * is included which does not include this header file.
188  */
189 # include <sys/isa_defs.h>
190 # endif
191 #elif defined(_AIX) || defined(__TOS_AIX__)
192 # define U_PLATFORM U_PF_AIX
193 #elif defined(_hpux) || defined(hpux) || defined(__hpux)
194 # define U_PLATFORM U_PF_HPUX
195 #elif defined(sgi) || defined(__sgi)
196 # define U_PLATFORM U_PF_IRIX
197 #elif defined(__QNX__) || defined(__QNXNTO__)
198 # define U_PLATFORM U_PF_QNX
199 #elif defined(__TOS_MVS__)
200 # define U_PLATFORM U_PF_OS390
201 #elif defined(__OS400__) || defined(__TOS_OS400__)
202 # define U_PLATFORM U_PF_OS400
203 #elif defined(__EMSCRIPTEN__)
204 # define U_PLATFORM U_PF_EMSCRIPTEN
205 #else
206 # define U_PLATFORM U_PF_UNKNOWN
207 #endif
208 
216 #if (defined(_MSC_VER) && !(defined(__clang__) && __clang__)) || defined(U_IN_DOXYGEN)
217 # define U_REAL_MSVC
218 #endif
219 
226 /* Commented out because this is already set in mh-cygwin-msvc
227 #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER)
228 # define CYGWINMSVC
229 #endif
230 */
231 #ifdef U_IN_DOXYGEN
232 # define CYGWINMSVC
233 #endif
234 
241 #ifdef U_PLATFORM_USES_ONLY_WIN32_API
242  /* Use the predefined value. */
243 #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC)
244 # define U_PLATFORM_USES_ONLY_WIN32_API 1
245 #else
246  /* Cygwin implements POSIX. */
247 # define U_PLATFORM_USES_ONLY_WIN32_API 0
248 #endif
249 
256 #ifdef U_PLATFORM_HAS_WIN32_API
257  /* Use the predefined value. */
258 #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
259 # define U_PLATFORM_HAS_WIN32_API 1
260 #else
261 # define U_PLATFORM_HAS_WIN32_API 0
262 #endif
263 
270 #ifdef U_PLATFORM_HAS_WINUWP_API
271  /* Use the predefined value. */
272 #else
273 # define U_PLATFORM_HAS_WINUWP_API 0
274 #endif
275 
282 #ifdef U_PLATFORM_IMPLEMENTS_POSIX
283  /* Use the predefined value. */
284 #elif U_PLATFORM_USES_ONLY_WIN32_API
285 # define U_PLATFORM_IMPLEMENTS_POSIX 0
286 #else
287 # define U_PLATFORM_IMPLEMENTS_POSIX 1
288 #endif
289 
295 #ifdef U_PLATFORM_IS_LINUX_BASED
296  /* Use the predefined value. */
297 #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499
298 # define U_PLATFORM_IS_LINUX_BASED 1
299 #else
300 # define U_PLATFORM_IS_LINUX_BASED 0
301 #endif
302 
308 #ifdef U_PLATFORM_IS_DARWIN_BASED
309  /* Use the predefined value. */
310 #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE
311 # define U_PLATFORM_IS_DARWIN_BASED 1
312 #else
313 # define U_PLATFORM_IS_DARWIN_BASED 0
314 #endif
315 
316 /*===========================================================================*/
318 /*===========================================================================*/
319 
330 #ifdef __GNUC__
331 # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__)
332 #else
333 # define U_GCC_MAJOR_MINOR 0
334 #endif
335 
341 #ifdef U_IS_BIG_ENDIAN
342  /* Use the predefined value. */
343 #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN)
344 # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN)
345 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
346  /* gcc */
347 # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
348 #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
349 # define U_IS_BIG_ENDIAN 1
350 #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN)
351 # define U_IS_BIG_ENDIAN 0
352 #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__)
353  /* These platforms do not appear to predefine any endianness macros. */
354 # define U_IS_BIG_ENDIAN 1
355 #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0)
356  /* HPPA do not appear to predefine any endianness macros. */
357 # define U_IS_BIG_ENDIAN 1
358 #elif defined(sparc) || defined(__sparc) || defined(__sparc__)
359  /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */
360 # define U_IS_BIG_ENDIAN 1
361 #else
362 # define U_IS_BIG_ENDIAN 0
363 #endif
364 
370 #ifdef U_HAVE_PLACEMENT_NEW
371  /* Use the predefined value. */
372 #elif defined(__BORLANDC__)
373 # define U_HAVE_PLACEMENT_NEW 0
374 #else
375 # define U_HAVE_PLACEMENT_NEW 1
376 #endif
377 
384 #ifdef U_HAVE_DEBUG_LOCATION_NEW
385  /* Use the predefined value. */
386 #elif defined(_MSC_VER)
387 # define U_HAVE_DEBUG_LOCATION_NEW 1
388 #else
389 # define U_HAVE_DEBUG_LOCATION_NEW 0
390 #endif
391 
392 /* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */
393 #ifdef __has_attribute
394 # define UPRV_HAS_ATTRIBUTE(x) __has_attribute(x)
395 #else
396 # define UPRV_HAS_ATTRIBUTE(x) 0
397 #endif
398 #ifdef __has_cpp_attribute
399 # define UPRV_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
400 #else
401 # define UPRV_HAS_CPP_ATTRIBUTE(x) 0
402 #endif
403 #ifdef __has_declspec_attribute
404 # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) __has_declspec_attribute(x)
405 #else
406 # define UPRV_HAS_DECLSPEC_ATTRIBUTE(x) 0
407 #endif
408 #ifdef __has_builtin
409 # define UPRV_HAS_BUILTIN(x) __has_builtin(x)
410 #else
411 # define UPRV_HAS_BUILTIN(x) 0
412 #endif
413 #ifdef __has_feature
414 # define UPRV_HAS_FEATURE(x) __has_feature(x)
415 #else
416 # define UPRV_HAS_FEATURE(x) 0
417 #endif
418 #ifdef __has_extension
419 # define UPRV_HAS_EXTENSION(x) __has_extension(x)
420 #else
421 # define UPRV_HAS_EXTENSION(x) 0
422 #endif
423 #ifdef __has_warning
424 # define UPRV_HAS_WARNING(x) __has_warning(x)
425 #else
426 # define UPRV_HAS_WARNING(x) 0
427 #endif
428 
429 
430 #if defined(__clang__)
431 #define UPRV_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
432 #else
433 #define UPRV_NO_SANITIZE_UNDEFINED
434 #endif
435 
441 #if defined(__GNUC__) && __GNUC__>=3
442 # define U_MALLOC_ATTR __attribute__ ((__malloc__))
443 #else
444 # define U_MALLOC_ATTR
445 #endif
446 
452 #if (defined(__GNUC__) && \
453  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
454  UPRV_HAS_ATTRIBUTE(alloc_size)
455 # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X)))
456 # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y)))
457 #else
458 # define U_ALLOC_SIZE_ATTR(X)
459 # define U_ALLOC_SIZE_ATTR2(X,Y)
460 #endif
461 
468 #ifdef U_CPLUSPLUS_VERSION
469 # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus)
470 # undef U_CPLUSPLUS_VERSION
471 # define U_CPLUSPLUS_VERSION 0
472 # endif
473  /* Otherwise use the predefined value. */
474 #elif !defined(__cplusplus)
475 # define U_CPLUSPLUS_VERSION 0
476 #elif __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
477 # define U_CPLUSPLUS_VERSION 17
478 #elif __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
479 # define U_CPLUSPLUS_VERSION 14
480 #elif __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
481 # define U_CPLUSPLUS_VERSION 11
482 #else
483  // C++98 or C++03
484 # define U_CPLUSPLUS_VERSION 1
485 #endif
486 
493 #ifndef __cplusplus
494  // Not for C.
495 #elif defined(U_FALLTHROUGH)
496  // Use the predefined value.
497 #elif defined(__clang__)
498  // Test for compiler vs. feature separately.
499  // Other compilers might choke on the feature test.
500 # if UPRV_HAS_CPP_ATTRIBUTE(clang::fallthrough) || \
501  (UPRV_HAS_FEATURE(cxx_attributes) && \
502  UPRV_HAS_WARNING("-Wimplicit-fallthrough"))
503 # define U_FALLTHROUGH [[clang::fallthrough]]
504 # endif
505 #elif defined(__GNUC__) && (__GNUC__ >= 7)
506 # define U_FALLTHROUGH __attribute__((fallthrough))
507 #endif
508 
509 #ifndef U_FALLTHROUGH
510 # define U_FALLTHROUGH
511 #endif
512 
515 /*===========================================================================*/
517 /*===========================================================================*/
518 
523 #define U_ASCII_FAMILY 0
524 
529 #define U_EBCDIC_FAMILY 1
530 
573 #ifdef U_CHARSET_FAMILY
574  /* Use the predefined value. */
575 #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB)
576 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
577 #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__)
578 # define U_CHARSET_FAMILY U_EBCDIC_FAMILY
579 #else
580 # define U_CHARSET_FAMILY U_ASCII_FAMILY
581 #endif
582 
603 #ifdef U_CHARSET_IS_UTF8
604  /* Use the predefined value. */
605 #elif U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED || \
606  U_PLATFORM == U_PF_EMSCRIPTEN
607 # define U_CHARSET_IS_UTF8 1
608 #else
609 # define U_CHARSET_IS_UTF8 0
610 #endif
611 
614 /*===========================================================================*/
616 /*===========================================================================*/
617 
624 #ifdef U_HAVE_WCHAR_H
625  /* Use the predefined value. */
626 #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9
627  /*
628  * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t.
629  * The type and header existed, but the library functions did not work as expected.
630  * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway.
631  */
632 # define U_HAVE_WCHAR_H 0
633 #else
634 # define U_HAVE_WCHAR_H 1
635 #endif
636 
643 #ifdef U_SIZEOF_WCHAR_T
644  /* Use the predefined value. */
645 #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9)
646  /*
647  * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring.
648  * Newer Mac OS X has size 4.
649  */
650 # define U_SIZEOF_WCHAR_T 1
651 #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN
652 # define U_SIZEOF_WCHAR_T 2
653 #elif U_PLATFORM == U_PF_AIX
654  /*
655  * AIX 6.1 information, section "Wide character data representation":
656  * "... the wchar_t datatype is 32-bit in the 64-bit environment and
657  * 16-bit in the 32-bit environment."
658  * and
659  * "All locales use Unicode for their wide character code values (process code),
660  * except the IBM-eucTW codeset."
661  */
662 # ifdef __64BIT__
663 # define U_SIZEOF_WCHAR_T 4
664 # else
665 # define U_SIZEOF_WCHAR_T 2
666 # endif
667 #elif U_PLATFORM == U_PF_OS390
668  /*
669  * z/OS V1R11 information center, section "LP64 | ILP32":
670  * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes.
671  * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes."
672  */
673 # ifdef _LP64
674 # define U_SIZEOF_WCHAR_T 4
675 # else
676 # define U_SIZEOF_WCHAR_T 2
677 # endif
678 #elif U_PLATFORM == U_PF_OS400
679 # if defined(__UTF32__)
680  /*
681  * LOCALETYPE(*LOCALEUTF) is specified.
682  * Wide-character strings are in UTF-32,
683  * narrow-character strings are in UTF-8.
684  */
685 # define U_SIZEOF_WCHAR_T 4
686 # elif defined(__UCS2__)
687  /*
688  * LOCALETYPE(*LOCALEUCS2) is specified.
689  * Wide-character strings are in UCS-2,
690  * narrow-character strings are in EBCDIC.
691  */
692 # define U_SIZEOF_WCHAR_T 2
693 # else
694  /*
695  * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified.
696  * Wide-character strings are in 16-bit EBCDIC,
697  * narrow-character strings are in EBCDIC.
698  */
699 # define U_SIZEOF_WCHAR_T 2
700 # endif
701 #else
702 # define U_SIZEOF_WCHAR_T 4
703 #endif
704 
705 #ifndef U_HAVE_WCSCPY
706 #define U_HAVE_WCSCPY U_HAVE_WCHAR_H
707 #endif
708 
719 #ifdef U_HAVE_CHAR16_T
720  /* Use the predefined value. */
721 #else
722  /*
723  * Notes:
724  * C++11 and C11 require support for UTF-16 literals
725  * Doesn't work on Mac C11 (see workaround in ptypes.h).
726  */
727 # if defined(__cplusplus) || !U_PLATFORM_IS_DARWIN_BASED
728 # define U_HAVE_CHAR16_T 1
729 # else
730 # define U_HAVE_CHAR16_T 0
731 # endif
732 #endif
733 
741 #ifdef U_DECLARE_UTF16
742  /* Use the predefined value. */
743 #elif U_HAVE_CHAR16_T \
744  || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \
745  || (defined(__HP_aCC) && __HP_aCC >= 035000) \
746  || (defined(__HP_cc) && __HP_cc >= 111106) \
747  || (defined(U_IN_DOXYGEN))
748 # define U_DECLARE_UTF16(string) u ## string
749 #elif U_SIZEOF_WCHAR_T == 2 \
750  && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__)))
751 # define U_DECLARE_UTF16(string) L ## string
752 #else
753  /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */
754 #endif
755 
758 /*===========================================================================*/
760 /*===========================================================================*/
761 
762 #ifdef U_EXPORT
763  /* Use the predefined value. */
764 #elif defined(U_STATIC_IMPLEMENTATION)
765 # define U_EXPORT
766 #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
767  UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
768 # define U_EXPORT __declspec(dllexport)
769 #elif defined(__GNUC__)
770 # define U_EXPORT __attribute__((visibility("default")))
771 #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \
772  || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550)
773 # define U_EXPORT __global
774 /*#elif defined(__HP_aCC) || defined(__HP_cc)
775 # define U_EXPORT __declspec(dllexport)*/
776 #else
777 # define U_EXPORT
778 #endif
779 
780 /* U_CALLCONV is related to U_EXPORT2 */
781 #ifdef U_EXPORT2
782  /* Use the predefined value. */
783 #elif defined(_MSC_VER)
784 # define U_EXPORT2 __cdecl
785 #else
786 # define U_EXPORT2
787 #endif
788 
789 #ifdef U_IMPORT
790  /* Use the predefined value. */
791 #elif defined(_MSC_VER) || (UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllexport__) && \
792  UPRV_HAS_DECLSPEC_ATTRIBUTE(__dllimport__))
793  /* Windows needs to export/import data. */
794 # define U_IMPORT __declspec(dllimport)
795 #else
796 # define U_IMPORT
797 #endif
798 
806 #ifdef U_HIDDEN
807  /* Use the predefined value. */
808 #elif defined(__GNUC__)
809 # define U_HIDDEN __attribute__((visibility("hidden")))
810 #else
811 # define U_HIDDEN
812 #endif
813 
831 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
832 # define U_CALLCONV __cdecl
833 #else
834 # define U_CALLCONV U_EXPORT2
835 #endif
836 
842 #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus)
843 # define U_CALLCONV_FPTR U_CALLCONV
844 #else
845 # define U_CALLCONV_FPTR
846 #endif
849 #endif // _PLATFORM_H
User-configurable settings.
C API: definitions of ICU version numbers.