mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-12-27 07:54:51 +01:00
Change PLATFORM_32/64BIT detection
turns out that using UINTPTR_MAX is a pain on several systems like FreeBSD or even older Linux/glibc systems, so maybe let's not do that anymore. Now I check for known CPU-architectures instead. I also added some sanity checks to make sure the detection was correct.
This commit is contained in:
parent
83b3e2fee3
commit
e642cbcd20
|
@ -61,37 +61,44 @@ typedef unsigned int UINT;
|
||||||
#define PLATFORM_LITTLEENDIAN 1
|
#define PLATFORM_LITTLEENDIAN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PLATFORM_WIN32
|
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_ARCH_PPC64) \
|
||||||
#ifdef _WIN64
|
|| defined(_M_IA64) || defined(__IA64__)
|
||||||
#define PLATFORM_64BIT 1
|
|
||||||
#else
|
#define PLATFORM_64BIT 1
|
||||||
#define PLATFORM_32BIT 1
|
|
||||||
#endif
|
#elif defined(__i386) || defined(_M_IX86) || defined(__arm__) || defined(_M_ARM) || defined(__POWERPC__) \
|
||||||
|
|| defined(_M_PPC) || defined(_ARCH_PPC)
|
||||||
|
|
||||||
|
#define PLATFORM_32BIT 1
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// AFAIK there were versions of MSVC where UINTPTR_MAX was incorrect,
|
#error "Unknown CPU-Architecture, adapt this code to detect 32/64bitness of your system!"
|
||||||
// so I use different code for Windows above
|
|
||||||
#include <stdint.h> // UINTPTR_MAX
|
|
||||||
#ifdef UINTPTR_MAX
|
|
||||||
#if UINTPTR_MAX == 0xffffffffuL
|
|
||||||
#define PLATFORM_32BIT 1
|
|
||||||
#elif UINTPTR_MAX == 0xffffffffffffffffuLL
|
|
||||||
#define PLATFORM_64BIT 1
|
|
||||||
#else
|
|
||||||
#error WTF, your system seems to be neither 32bit nor 64bit?!
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#error Your system does not provide UINTPRT_MAX, find another way!
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if UINTPTR_MAX != SIZE_MAX
|
|
||||||
// the code uses size_t to store pointers all over the place, so if size_t and uintptr_t
|
|
||||||
// don't have the same size on your system, you're in real trouble.
|
|
||||||
// (before panicking however make sure your headers don't just contain bullshit values for UINTPTR_MAX or SIZE_MAX)
|
|
||||||
#error Seems like on your system sizeof(size_t) != sizeof(uintptr_t) - that is *very* bad.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// if the compiler complains about the typedef created by MY_STATIC_ASSERT being invalid
|
||||||
|
// (because of array with negative size), it means the check for cond has failed
|
||||||
|
#define MY_STATIC_ASSERT(namesuffx, cond) \
|
||||||
|
typedef char sesam__check_ ## namesuffx [ (cond) ? 1 : -1 ];
|
||||||
|
|
||||||
|
// some sanity checks to make sure the PLATFORM_*BIT #defines match the pointer size
|
||||||
|
// and that size_t is the size of a pointer, as expected (as we sometimes use size_t to store pointers)
|
||||||
|
#ifdef PLATFORM_32BIT
|
||||||
|
MY_STATIC_ASSERT(32bit_PointerSize, sizeof(void*) == 4);
|
||||||
|
|
||||||
|
#ifdef PLATFORM_64BIT
|
||||||
|
#error "PLATFORM_32BIT and PLATFORM_64BIT must not be #defined at the same time!"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PLATFORM_64BIT
|
||||||
|
MY_STATIC_ASSERT(64bit_PointerSize, sizeof(void*) == 8);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MY_STATIC_ASSERT(size_tSize, sizeof(size_t) == sizeof(void*));
|
||||||
|
|
||||||
|
#undef MY_STATIC_ASSERT
|
||||||
|
|
||||||
// Mac symbols have an underscore prepended...
|
// Mac symbols have an underscore prepended...
|
||||||
#if PLATFORM_MACOSX
|
#if PLATFORM_MACOSX
|
||||||
#define ASMSYM(x) "_" #x
|
#define ASMSYM(x) "_" #x
|
||||||
|
|
Loading…
Reference in New Issue
Block a user