84 #ifndef INCLUDED_eacompilertraits_H 85 #define INCLUDED_eacompilertraits_H 87 #ifndef INCLUDED_eaplatform_H 88 #include <stk_util/util/eaplatform.h> 91 #ifndef INCLUDED_eacompiler_H 92 #include <stk_util/util/eacompiler.h> 97 #if defined(__MWERKS__) 101 #ifndef __STDC_LIMIT_MACROS 102 #define __STDC_LIMIT_MACROS 105 #ifndef __STDC_CONSTANT_MACROS 106 #define __STDC_CONSTANT_MACROS 112 #if defined(__SNC__) || defined(EA_PLATFORM_PS3) || defined(__S3E__) 113 #ifndef __STDC_LIMIT_MACROS 114 #define __STDC_LIMIT_MACROS 117 #ifndef __STDC_CONSTANT_MACROS 118 #define __STDC_CONSTANT_MACROS 123 #if !defined(EA_COMPILER_HAS_INTTYPES) 124 #if !defined(__S3E__) 125 #define EA_COMPILER_HAS_INTTYPES 131 #if defined(__STDC__) 132 #define EA_COMPILER_IS_ANSIC // The compiler claims to be ANSI C 144 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 145 #define EA_COMPILER_IS_C99 153 #if (defined(__USE_ISOC99) || (defined(_MSL_C99) && (_MSL_C99 == 1))) && !defined(EA_COMPILER_IS_C99) 154 #define EA_COMPILER_IS_C99 158 #if (defined(_MSL_C99) && (_MSL_C99 == 1)) 159 #define EA_COMPILER_HAS_C99_TYPES 162 #if defined(__GNUC__) 163 #if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 302) // Also, GCC defines _HAS_C9X. 164 #define EA_COMPILER_HAS_C99_TYPES // The compiler is not necessarily a C99 compiler, but it defines C99 types. 166 #ifndef __STDC_LIMIT_MACROS 167 #define __STDC_LIMIT_MACROS 170 #ifndef __STDC_CONSTANT_MACROS 171 #define __STDC_CONSTANT_MACROS // This tells the GCC compiler that we want it to use its native C99 types. 177 #define EA_COMPILER_IS_CPLUSPLUS 184 #ifdef EA_COMPILER_MSVC 185 #if EA_COMPILER_VERSION >= 1300 187 #define EA_COMPILER_MANAGED_CPP 230 #if defined(EA_COMPILER_SN) && defined(__GNUC__) // If using the SN compiler in GCC compatibility mode... 231 #define EA_ALIGN_OF(type) ((size_t)__alignof__(type)) 232 #define EA_ALIGN(n) __attribute__((aligned(n))) 233 #define EA_PREFIX_ALIGN(n) 234 #define EA_POSTFIX_ALIGN(n) __attribute__((aligned(n))) 235 #define EA_ALIGNED(variable_type, variable, n) variable_type variable __attribute__((aligned(n))) 236 #define EA_PACKED __attribute__((packed)) 239 #elif defined(__GNUC__) && (__GNUC__ < 3) 240 #define EA_ALIGN_OF(type) ((size_t)__alignof__(type)) 242 #define EA_PREFIX_ALIGN(n) 243 #define EA_POSTFIX_ALIGN(n) __attribute__((aligned(n))) 244 #define EA_ALIGNED(variable_type, variable, n) variable_type variable __attribute__((aligned(n))) 245 #define EA_PACKED __attribute__((packed)) 248 #elif (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__xlC__) 249 #define EA_ALIGN_OF(type) ((size_t)__alignof__(type)) 250 #define EA_ALIGN(n) __attribute__((aligned(n))) 251 #define EA_PREFIX_ALIGN(n) 252 #define EA_POSTFIX_ALIGN(n) __attribute__((aligned(n))) 253 #define EA_ALIGNED(variable_type, variable, n) variable_type variable __attribute__((aligned(n))) 254 #define EA_PACKED __attribute__((packed)) 258 #elif defined(EA_COMPILER_METROWERKS) 259 #define EA_ALIGN_OF(type) ((size_t)__alignof__(type)) 260 #define EA_ALIGN(n) __attribute__((aligned(n))) 261 #define EA_PREFIX_ALIGN(n) 262 #define EA_POSTFIX_ALIGN(n) __attribute__((aligned(n))) 263 #define EA_ALIGNED(variable_type, variable, n) variable_type variable __attribute__((aligned(n))) 269 #elif defined(EA_COMPILER_INTEL) || defined(EA_PLATFORM_XBOX) || (defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1300)) 270 #define EA_ALIGN_OF(type) ((size_t)__alignof(type)) 271 #define EA_ALIGN(n) __declspec(align(n)) 272 #define EA_PREFIX_ALIGN(n) __declspec(align(n)) 273 #define EA_POSTFIX_ALIGN(n) 274 #define EA_ALIGNED(variable_type, variable, n) __declspec(align(n)) variable_type variable 278 #elif defined(__ARMCC_VERSION) 279 #define EA_ALIGN_OF(type) ((size_t)__ALIGNOF__(type)) 280 #define EA_ALIGN(n) __align(n) 281 #define EA_PREFIX_ALIGN(n) __align(n) 282 #define EA_POSTFIX_ALIGN(n) 283 #define EA_ALIGNED(variable_type, variable, n) __align(n) variable_type variable 284 #define EA_PACKED __packed 286 #else // Unusual compilers 292 #define EA_PREFIX_ALIGN(n) 293 #define EA_POSTFIX_ALIGN(n) 294 #define EA_ALIGNED(variable_type, variable, n) variable_type variable 298 template <
typename T>
struct EAAlignOf1 {
enum { s =
sizeof (T), value = s ^ (s & (s - 1)) }; };
299 template <
typename T>
struct EAAlignOf2;
300 template <
int size_diff>
struct helper {
template <
typename T>
struct Val {
enum { value = size_diff }; }; };
301 template <>
struct helper<0> {
template <
typename T>
struct Val {
enum { value = EAAlignOf2<T>::value }; }; };
302 template <
typename T>
struct EAAlignOf2 {
struct Big { T x;
char c; };
303 enum { diff =
sizeof (Big) -
sizeof (T), value = helper<diff>::template Val<Big>::value }; };
304 template <
typename T>
struct EAAlignof3 {
enum { x = EAAlignOf2<T>::value, y = EAAlignOf1<T>::value, value = x < y ? x : y }; };
305 #define EA_ALIGN_OF(type) ((size_t)EAAlignof3<type>::value) 312 #define EA_ALIGN_OF(type) ((size_t)offsetof(struct { char c; type m; }, m)) 338 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__MWERKS__) // Metrowerks supports __builtin_expect, but with some platforms (e.g. Wii) it appears to ignore it. 339 #if defined(__cplusplus) 340 #define EA_LIKELY(x) __builtin_expect(!!(x), true) 341 #define EA_UNLIKELY(x) __builtin_expect(!!(x), false) 343 #define EA_LIKELY(x) __builtin_expect(!!(x), 1) 344 #define EA_UNLIKELY(x) __builtin_expect(!!(x), 0) 347 #define EA_LIKELY(x) (x) 348 #define EA_UNLIKELY(x) (x) 363 #if !defined(EA_INIT_PRIORITY) 364 #if defined(__GNUC__) 365 #define EA_INIT_PRIORITY(x) __attribute__ ((init_priority (x))) 367 #define EA_INIT_PRIORITY(x) 387 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 303) 388 #define EA_MAY_ALIAS __attribute__((__may_alias__)) 416 #if defined(_MSC_VER) && (_MSC_VER >= 1300) // If VC7.0 and later (including XBox, and XBox 360)... 417 #define EA_ASSUME(x) __assume(x) 444 #if defined(EA_COMPILER_GNUC) 445 #define EA_PURE __attribute__((pure)) 446 #elif defined(__ARMCC_VERSION) // Arm brand compiler for ARM CPU 447 #define EA_PURE __pure 475 #if defined(_MSC_VER) && (_MSC_VER >= 1300) // If VC7.0 and later (including XBox)... 476 #define EA_WEAK __declspec(selectany) 477 #define EA_WEAK_SUPPORTED 1 478 #elif defined(_MSC_VER) || (defined(__GNUC__) && defined(__CYGWIN__)) 480 #define EA_WEAK_SUPPORTED 0 481 #elif defined(__ARMCC_VERSION) // Arm brand compiler for ARM CPU 482 #define EA_WEAK __weak 483 #define EA_WEAK_SUPPORTED 1 484 #else // GCC and IBM compilers, others. 485 #define EA_WEAK __attribute__((weak)) 486 #define EA_WEAK_SUPPORTED 1 498 #ifndef EA_WCHAR_T_NON_NATIVE 505 #if defined(EA_COMPILER_INTEL) 506 #if (EA_COMPILER_VERSION < 700) 507 #define EA_WCHAR_T_NON_NATIVE 1 509 #if (!defined(_WCHAR_T_DEFINED) && !defined(_WCHAR_T)) 510 #define EA_WCHAR_T_NON_NATIVE 1 513 #elif defined(EA_COMPILER_MSVC) || defined(EA_COMPILER_BORLAND) 514 #ifndef _NATIVE_WCHAR_T_DEFINED 515 #define EA_WCHAR_T_NON_NATIVE 1 517 #elif defined(EA_COMPILER_METROWERKS) 518 #if !__option(wchar_type) 519 #define EA_WCHAR_T_NON_NATIVE 1 521 #elif defined(__SNC__) && !defined(__cplusplus) // If compiling C under SNC... 522 #define EA_WCHAR_T_NON_NATIVE 1 526 #ifndef EA_WCHAR_SIZE // If the user hasn't specified that it is a given size... 527 #if defined(__WCHAR_MAX__) // GCC defines this for most platforms. 528 #if (__WCHAR_MAX__ == 2147483647) || (__WCHAR_MAX__ == 4294967295) 529 #define EA_WCHAR_SIZE 4 530 #elif (__WCHAR_MAX__ == 32767) || (__WCHAR_MAX__ == 65535) 531 #define EA_WCHAR_SIZE 2 532 #elif (__WCHAR_MAX__ == 127) || (__WCHAR_MAX__ == 255) 533 #define EA_WCHAR_SIZE 1 535 #define EA_WCHAR_SIZE 4 537 #elif defined(WCHAR_MAX) // The SN and Arm compilers define this. 538 #if (WCHAR_MAX == 2147483647) || (WCHAR_MAX == 4294967295) 539 #define EA_WCHAR_SIZE 4 540 #elif (WCHAR_MAX == 32767) || (WCHAR_MAX == 65535) 541 #define EA_WCHAR_SIZE 2 542 #elif (WCHAR_MAX == 127) || (WCHAR_MAX == 255) 543 #define EA_WCHAR_SIZE 1 545 #define EA_WCHAR_SIZE 4 547 #elif defined(_WCMAX) // The SN and Arm compilers define this. 548 #if (_WCMAX == 2147483647) || (_WCMAX == 4294967295) 549 #define EA_WCHAR_SIZE 4 550 #elif (_WCMAX == 32767) || (_WCMAX == 65535) 551 #define EA_WCHAR_SIZE 2 552 #elif (_WCMAX == 127) || (_WCMAX == 255) 553 #define EA_WCHAR_SIZE 1 555 #define EA_WCHAR_SIZE 4 557 #elif defined(EA_PLATFORM_UNIX) || defined(EA_PLATFORM_PS3) || defined(EA_PLATFORM_PS3_SPU) 563 #define EA_WCHAR_SIZE 4 573 #define EA_WCHAR_SIZE 2 589 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1400) // If VC8 (VS2005) or later... 590 #define EA_RESTRICT __restrict 591 #elif defined(EA_COMPILER_GNUC) 592 #define EA_RESTRICT __restrict // GCC defines 'restrict' (as opposed to __restrict) in C99 mode only. 593 #elif defined(__ARMCC_VERSION) 594 #define EA_RESTRICT __restrict 595 #elif defined(__MWERKS__) 597 #define EA_RESTRICT restrict 601 #elif defined(EA_COMPILER_IS_C99) 602 #define EA_RESTRICT restrict 624 #ifndef EA_DEPRECATED 625 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION > 1300) // If VC7 (VS2003) or later... 626 #define EA_DEPRECATED __declspec(deprecated) 627 #elif defined(EA_COMPILER_MSVC) 628 #define EA_DEPRECATED 630 #define EA_DEPRECATED __attribute__((deprecated)) 634 #ifndef EA_PREFIX_DEPRECATED 635 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION > 1300) // If VC7 (VS2003) or later... 636 #define EA_PREFIX_DEPRECATED __declspec(deprecated) 637 #define EA_POSTFIX_DEPRECATED 638 #elif defined(EA_COMPILER_MSVC) 639 #define EA_PREFIX_DEPRECATED 640 #define EA_POSTFIX_DEPRECATED 642 #define EA_PREFIX_DEPRECATED 643 #define EA_POSTFIX_DEPRECATED __attribute__((deprecated)) 668 #ifndef EA_FORCE_INLINE 669 #if defined(EA_COMPILER_MSVC) 670 #define EA_FORCE_INLINE __forceinline 671 #elif defined(EA_COMPILER_GNUC) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 301) 672 #if defined(__cplusplus) 673 #define EA_FORCE_INLINE inline __attribute__((always_inline)) 675 #define EA_FORCE_INLINE __inline__ __attribute__((always_inline)) 678 #if defined(__cplusplus) 679 #define EA_FORCE_INLINE inline 681 #define EA_FORCE_INLINE __inline 686 #if defined(EA_COMPILER_SN) && defined(EA_PLATFORM_PS3) // SN's implementation of always_inline is broken and sometimes fails to link the function. 687 #define EA_PREFIX_FORCE_INLINE inline 688 #define EA_POSTFIX_FORCE_INLINE 689 #elif defined(EA_COMPILER_GNUC) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 301) 690 #define EA_PREFIX_FORCE_INLINE inline 691 #define EA_POSTFIX_FORCE_INLINE __attribute__((always_inline)) 693 #define EA_PREFIX_FORCE_INLINE inline 694 #define EA_POSTFIX_FORCE_INLINE 721 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1400) // If VC8 (VS2005) or later... 722 #define EA_NO_INLINE __declspec(noinline) 723 #elif defined(EA_COMPILER_MSVC) 726 #define EA_NO_INLINE __attribute__((noinline)) 730 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1400) // If VC8 (VS2005) or later... 731 #define EA_PREFIX_NO_INLINE __declspec(noinline) 732 #define EA_POSTFIX_NO_INLINE 733 #elif defined(EA_COMPILER_MSVC) 734 #define EA_PREFIX_NO_INLINE 735 #define EA_POSTFIX_NO_INLINE 737 #define EA_PREFIX_NO_INLINE 738 #define EA_POSTFIX_NO_INLINE __attribute__((noinline)) 754 #ifdef EA_COMPILER_MSVC 755 #define EA_NO_VTABLE __declspec(novtable) 756 #define EA_CLASS_NO_VTABLE(x) class __declspec(novtable) x 757 #define EA_STRUCT_NO_VTABLE(x) struct __declspec(novtable) x 760 #define EA_CLASS_NO_VTABLE(x) class x 761 #define EA_STRUCT_NO_VTABLE(x) struct x 782 #if defined(EA_COMPILER_MSVC) 783 #define EA_PASCAL __stdcall 784 #elif defined(EA_COMPILER_GNUC) && defined(EA_PROCESSOR_X86) 785 #define EA_PASCAL __attribute__((stdcall)) 786 #elif defined(EA_COMPILER_METROWERKS) && defined(EA_PLATFORM_WINDOWS) 789 #define EA_PASCAL pascal 799 #ifndef EA_PASCAL_FUNC 800 #if defined(EA_COMPILER_MSVC) 801 #define EA_PASCAL_FUNC(funcname_and_paramlist) __stdcall funcname_and_paramlist 802 #elif defined(EA_COMPILER_GNUC) && defined(EA_PROCESSOR_X86) 803 #define EA_PASCAL_FUNC(funcname_and_paramlist) __attribute__((stdcall)) funcname_and_paramlist 804 #elif defined(EA_COMPILER_METROWERKS) && defined(EA_PLATFORM_WINDOWS) 805 #define EA_PASCAL_FUNC(funcname_and_paramlist) pascal funcname_and_paramlist 807 #define EA_PASCAL_FUNC(funcname_and_paramlist) funcname_and_paramlist 818 #if defined(EA_COMPILER_GNUC) 819 #if defined(__SSE2__) 821 #elif defined(__SSE__) && __SSE__ 826 #elif defined(EA_PROCESSOR_X86) && defined(_MSC_FULL_VER) && !defined(__NOSSE__) && defined(_M_IX86_FP) 827 #define EA_SSE _M_IX86_FP 828 #elif defined(EA_PROCESSOR_X86) && defined(EA_COMPILER_INTEL) && !defined(__NOSSE__) 841 #if defined(EA_COMPILER_MSVC) 842 #define EA_IMPORT __declspec(dllimport) 855 #if defined(EA_COMPILER_MSVC) 856 #define EA_EXPORT __declspec(dllexport) 888 #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__GNUC__) || defined(__SNC__) || defined(__ICC) || defined(__ICL) 889 #define EA_PRAGMA_ONCE_SUPPORTED 1 899 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1400) // VS2005 (VC8) and later 900 #define EA_OVERRIDE override 913 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1400) // VS2005 (VC8) and later 914 #define EA_SEALED sealed 927 #if defined(EA_COMPILER_MSVC) && (EA_COMPILER_VERSION >= 1400) // VS2005 (VC8) and later 928 #define EA_ABSTRACT abstract 935 #endif // Header include guard