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 27 /** 28 * \file 29 * \brief Basic types for the platform. 30 * 31 * This file used to be generated by autoconf/configure. 32 * Starting with ICU 49, platform.h is a normal source file, 33 * to simplify cross-compiling and working with non-autoconf/make build systems. 34 * 35 * When a value in this file does not work on a platform, then please 36 * try to derive it from the U_PLATFORM value 37 * (for which we might need a new value constant in rare cases) 38 * and/or from other macros that are predefined by the compiler 39 * or defined in standard (POSIX or platform or compiler) headers. 40 * 41 * As a temporary workaround, you can add an explicit \#define for some macros 42 * before it is first tested, or add an equivalent -D macro definition 43 * to the compiler's command line. 44 * 45 * Note: Some compilers provide ways to show the predefined macros. 46 * For example, with gcc you can compile an empty .c file and have the compiler 47 * print the predefined macros with 48 * \code 49 * gcc -E -dM -x c /dev/null | sort 50 * \endcode 51 * (You can provide an actual empty .c file rather than /dev/null. 52 * <code>-x c++</code> is for C++.) 53 */ 54 55 /** 56 * Define some things so that they can be documented. 57 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 58 */ 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 \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 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 68 /** 69 * \def U_PLATFORM 70 * The U_PLATFORM macro defines the platform we're on. 71 * 72 * We used to define one different, value-less macro per platform. 73 * That made it hard to know the set of relevant platforms and macros, 74 * and hard to deal with variants of platforms. 75 * 76 * Starting with ICU 49, we define platforms as numeric macros, 77 * with ranges of values for related platforms and their variants. 78 * The U_PLATFORM macro is set to one of these values. 79 * 80 * Historical note from the Solaris Wikipedia article: 81 * AT&T and Sun collaborated on a project to merge the most popular Unix variants 82 * on the market at that time: BSD, System V, and Xenix. 83 * This became Unix System V Release 4 (SVR4). 84 * 85 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 86 */ 87 88 /** Unknown platform. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 89 #define U_PF_UNKNOWN 0 90 /** Windows \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 91 #define U_PF_WINDOWS 1000 92 /** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 93 #define U_PF_MINGW 1800 94 /** 95 * Cygwin. Windows, calls to cygwin1.dll for Posix functions, 96 * using MSVC or GNU gcc and binutils. 97 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 98 */ 99 #define U_PF_CYGWIN 1900 100 /* Reserve 2000 for U_PF_UNIX? */ 101 /** HP-UX is based on UNIX System V. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 102 #define U_PF_HPUX 2100 103 /** Solaris is a Unix operating system based on SVR4. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 104 #define U_PF_SOLARIS 2600 105 /** BSD is a UNIX operating system derivative. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 106 #define U_PF_BSD 3000 107 /** AIX is based on UNIX System V Releases and 4.3 BSD. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 108 #define U_PF_AIX 3100 109 /** IRIX is based on UNIX System V with BSD extensions. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 110 #define U_PF_IRIX 3200 111 /** 112 * Darwin is a POSIX-compliant operating system, composed of code developed by Apple, 113 * as well as code derived from NeXTSTEP, BSD, and other projects, 114 * built around the Mach kernel. 115 * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based. 116 * (Original description modified from WikiPedia.) 117 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 118 */ 119 #define U_PF_DARWIN 3500 120 /** iPhone OS (iOS) is a derivative of Mac OS X. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 121 #define U_PF_IPHONE 3550 122 /** QNX is a commercial Unix-like real-time operating system related to BSD. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 123 #define U_PF_QNX 3700 124 /** Linux is a Unix-like operating system. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 125 #define U_PF_LINUX 4000 126 /** 127 * Native Client is pretty close to Linux. 128 * See https://developer.chrome.com/native-client and 129 * http://www.chromium.org/nativeclient 130 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 131 */ 132 #define U_PF_BROWSER_NATIVE_CLIENT 4020 133 /** Android is based on Linux. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 134 #define U_PF_ANDROID 4050 135 /** Fuchsia is a POSIX-ish platform. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 136 #define U_PF_FUCHSIA 4100 137 /* Maximum value for Linux-based platform is 4499 */ 138 /** 139 * Emscripten is a C++ transpiler for the Web that can target asm.js or 140 * WebAssembly. It provides some POSIX-compatible wrappers and stubs and 141 * some Linux-like functionality, but is not fully compatible with 142 * either. 143 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 144 */ 145 #define U_PF_EMSCRIPTEN 5010 146 /** z/OS is the successor to OS/390 which was the successor to MVS. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 147 #define U_PF_OS390 9000 148 /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. */ 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 209 /** 210 * \def U_REAL_MSVC 211 * Defined if the compiler is the real MSVC compiler (and not something like 212 * Clang setting _MSC_VER in order to compile Windows code that requires it). 213 * Otherwise undefined. 214 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 215 */ 216 #if (defined(_MSC_VER) && !(defined(__clang__) && __clang__)) || defined(U_IN_DOXYGEN) 217 # define U_REAL_MSVC 218 #endif 219 220 /** 221 * \def CYGWINMSVC 222 * Defined if this is Windows with Cygwin, but using MSVC rather than gcc. 223 * Otherwise undefined. 224 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 225 */ 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 235 /** 236 * \def U_PLATFORM_USES_ONLY_WIN32_API 237 * Defines whether the platform uses only the Win32 API. 238 * Set to 1 for Windows/MSVC and MinGW but not Cygwin. 239 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 240 */ 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 250 /** 251 * \def U_PLATFORM_HAS_WIN32_API 252 * Defines whether the Win32 API is available on the platform. 253 * Set to 1 for Windows/MSVC, MinGW and Cygwin. 254 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 255 */ 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 264 /** 265 * \def U_PLATFORM_HAS_WINUWP_API 266 * Defines whether target is intended for Universal Windows Platform API 267 * Set to 1 for Windows10 Release Solution Configuration 268 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 269 */ 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 276 /** 277 * \def U_PLATFORM_IMPLEMENTS_POSIX 278 * Defines whether the platform implements (most of) the POSIX API. 279 * Set to 1 for Cygwin and most other platforms. 280 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 281 */ 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 290 /** 291 * \def U_PLATFORM_IS_LINUX_BASED 292 * Defines whether the platform is Linux or one of its derivatives. 293 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 294 */ 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 303 /** 304 * \def U_PLATFORM_IS_DARWIN_BASED 305 * Defines whether the platform is Darwin or one of its derivatives. 306 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 307 */ 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 /*===========================================================================*/ 317 /** @{ Compiler and environment features */ 318 /*===========================================================================*/ 319 320 /** 321 * \def U_GCC_MAJOR_MINOR 322 * Indicates whether the compiler is gcc (test for != 0), 323 * and if so, contains its major (times 100) and minor version numbers. 324 * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0. 325 * 326 * For example, for testing for whether we have gcc, and whether it's 4.6 or higher, 327 * use "#if U_GCC_MAJOR_MINOR >= 406". 328 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 329 */ 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 336 /** 337 * \def U_IS_BIG_ENDIAN 338 * Determines the endianness of the platform. 339 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 340 */ 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 365 /** 366 * \def U_HAVE_PLACEMENT_NEW 367 * Determines whether to override placement new and delete for STL. 368 * \xrefitem stable "Stable" "Stable List" ICU 2.6 369 */ 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 378 /** 379 * \def U_HAVE_DEBUG_LOCATION_NEW 380 * Define this to define the MFC debug version of the operator new. 381 * 382 * \xrefitem stable "Stable" "Stable List" ICU 3.4 383 */ 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 436 /** 437 * \def U_MALLOC_ATTR 438 * Attribute to mark functions as malloc-like 439 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 440 */ 441 #if defined(__GNUC__) && __GNUC__>=3 442 # define U_MALLOC_ATTR __attribute__ ((__malloc__)) 443 #else 444 # define U_MALLOC_ATTR 445 #endif 446 447 /** 448 * \def U_ALLOC_SIZE_ATTR 449 * Attribute to specify the size of the allocated buffer for malloc-like functions 450 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 451 */ 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 462 /** 463 * \def U_CPLUSPLUS_VERSION 464 * 0 if no C++; 1, 11, 14, ... if C++. 465 * Support for specific features cannot always be determined by the C++ version alone. 466 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 467 */ 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 487 /** 488 * \def U_FALLTHROUGH 489 * Annotate intentional fall-through between switch labels. 490 * http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough 491 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 492 */ 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 513 /** @} */ 514 515 /*===========================================================================*/ 516 /** @{ Character data types */ 517 /*===========================================================================*/ 518 519 /** 520 * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform. 521 * \xrefitem stable "Stable" "Stable List" ICU 2.0 522 */ 523 #define U_ASCII_FAMILY 0 524 525 /** 526 * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform. 527 * \xrefitem stable "Stable" "Stable List" ICU 2.0 528 */ 529 #define U_EBCDIC_FAMILY 1 530 531 /** 532 * \def U_CHARSET_FAMILY 533 * 534 * <p>These definitions allow to specify the encoding of text 535 * in the char data type as defined by the platform and the compiler. 536 * It is enough to determine the code point values of "invariant characters", 537 * which are the ones shared by all encodings that are in use 538 * on a given platform.</p> 539 * 540 * <p>Those "invariant characters" should be all the uppercase and lowercase 541 * latin letters, the digits, the space, and "basic punctuation". 542 * Also, '\\n', '\\r', '\\t' should be available.</p> 543 * 544 * <p>The list of "invariant characters" is:<br> 545 * \code 546 * A-Z a-z 0-9 SPACE " % & ' ( ) * + , - . / : ; < = > ? _ 547 * \endcode 548 * <br> 549 * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p> 550 * 551 * <p>This matches the IBM Syntactic Character Set (CS 640).</p> 552 * 553 * <p>In other words, all the graphic characters in 7-bit ASCII should 554 * be safely accessible except the following:</p> 555 * 556 * \code 557 * '\' <backslash> 558 * '[' <left bracket> 559 * ']' <right bracket> 560 * '{' <left brace> 561 * '}' <right brace> 562 * '^' <circumflex> 563 * '~' <tilde> 564 * '!' <exclamation mark> 565 * '#' <number sign> 566 * '|' <vertical line> 567 * '$' <dollar sign> 568 * '@' <commercial at> 569 * '`' <grave accent> 570 * \endcode 571 * \xrefitem stable "Stable" "Stable List" ICU 2.0 572 */ 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 583 /** 584 * \def U_CHARSET_IS_UTF8 585 * 586 * Hardcode the default charset to UTF-8. 587 * 588 * If this is set to 1, then 589 * - ICU will assume that all non-invariant char*, StringPiece, std::string etc. 590 * contain UTF-8 text, regardless of what the system API uses 591 * - some ICU code will use fast functions like u_strFromUTF8() 592 * rather than the more general and more heavy-weight conversion API (ucnv.h) 593 * - ucnv_getDefaultName() always returns "UTF-8" 594 * - ucnv_setDefaultName() is disabled and will not change the default charset 595 * - static builds of ICU are smaller 596 * - more functionality is available with the UCONFIG_NO_CONVERSION build-time 597 * configuration option (see unicode/uconfig.h) 598 * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable 599 * 600 * \xrefitem stable "Stable" "Stable List" ICU 4.2 601 * @see UCONFIG_NO_CONVERSION 602 */ 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 612 /** @} */ 613 614 /*===========================================================================*/ 615 /** @{ Information about wchar support */ 616 /*===========================================================================*/ 617 618 /** 619 * \def U_HAVE_WCHAR_H 620 * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default. 621 * 622 * \xrefitem stable "Stable" "Stable List" ICU 2.0 623 */ 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 637 /** 638 * \def U_SIZEOF_WCHAR_T 639 * U_SIZEOF_WCHAR_T==sizeof(wchar_t) 640 * 641 * \xrefitem stable "Stable" "Stable List" ICU 2.0 642 */ 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 709 /** @} */ 710 711 /** 712 * \def U_HAVE_CHAR16_T 713 * Defines whether the char16_t type is available for UTF-16 714 * and u"abc" UTF-16 string literals are supported. 715 * This is a new standard type and standard string literal syntax in C++11 716 * but has been available in some compilers before. 717 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 718 */ 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 734 /** 735 * @{ 736 * \def U_DECLARE_UTF16 737 * Do not use this macro because it is not defined on all platforms. 738 * Use the UNICODE_STRING or U_STRING_DECL macros instead. 739 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 740 */ 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 756 /** @} */ 757 758 /*===========================================================================*/ 759 /** @{ Symbol import-export control */ 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 799 /** 800 * \def U_HIDDEN 801 * This is used to mark internal structs declared within external classes, 802 * to prevent the internal structs from having the same visibility as the 803 * class within which they are declared. 804 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 805 */ 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 814 /** 815 * \def U_CALLCONV 816 * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary 817 * in callback function typedefs to make sure that the calling convention 818 * is compatible. 819 * 820 * This is only used for non-ICU-API functions. 821 * When a function is a public ICU API, 822 * you must use the U_CAPI and U_EXPORT2 qualifiers. 823 * 824 * Please note, you need to use U_CALLCONV after the *. 825 * 826 * NO : "static const char U_CALLCONV *func( . . . )" 827 * YES: "static const char* U_CALLCONV func( . . . )" 828 * 829 * \xrefitem stable "Stable" "Stable List" ICU 2.0 830 */ 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 837 /** 838 * \def U_CALLCONV_FPTR 839 * Similar to U_CALLCONV, but only used on function pointers. 840 * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 841 */ 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 847 /** @} */ 848 849 #endif // _PLATFORM_H 850