mirror of https://github.com/CGAL/cgal
Better (in the sense of working) endianness detection.
This commit is contained in:
parent
a29fd3cb46
commit
fd6524b2fb
|
|
@ -108,14 +108,21 @@ namespace CGAL {
|
||||||
// Big endian or little endian machine.
|
// Big endian or little endian machine.
|
||||||
// ====================================
|
// ====================================
|
||||||
|
|
||||||
#include <boost/limits.hpp> // provides endianness macros
|
// We used to have a config program for this, but it
|
||||||
|
// is much more convenient to use the preprocessor.
|
||||||
#ifdef BOOST_BIG_ENDIAN
|
#if defined(__sparc) || defined(__sparc__) \
|
||||||
|
|| defined(_POWER) || defined(__powerpc__) \
|
||||||
|
|| defined(__ppc__) || defined(__hppa) \
|
||||||
|
|| defined(_MIPSEB) || defined(_POWER) \
|
||||||
|
|| defined(__s390__)
|
||||||
# define CGAL_BIG_ENDIAN
|
# define CGAL_BIG_ENDIAN
|
||||||
#elif defined BOOST_LITTLE_ENDIAN
|
#elif defined(__i386__) || defined(__alpha__) \
|
||||||
|
|| defined(__ia64) || defined(__ia64__) \
|
||||||
|
|| defined(_M_IX86) || defined(_M_IA64) \
|
||||||
|
|| defined(_M_ALPHA)
|
||||||
# define CGAL_LITTLE_ENDIAN
|
# define CGAL_LITTLE_ENDIAN
|
||||||
#else
|
#else
|
||||||
# error "Unknown endianness"
|
# error Unknown endianness
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Run-time check that our endianness macro is correctly defined.
|
||||||
|
|
||||||
|
#include <CGAL/config.h>
|
||||||
|
#include <CGAL/Testsuite/assert.h>
|
||||||
|
|
||||||
|
#if !defined CGAL_LITTLE_ENDIAN && !defined CGAL_BIG_ENDIAN
|
||||||
|
# error no endian macro defined
|
||||||
|
#endif
|
||||||
|
|
||||||
|
union T {
|
||||||
|
int testWord;
|
||||||
|
char testByte[sizeof(int)];
|
||||||
|
} endianTest;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
endianTest.testWord = 1;
|
||||||
|
if (endianTest.testByte[0] == 1) {
|
||||||
|
#ifdef CGAL_LITTLE_ENDIAN
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
CGAL_test_assert(false);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef CGAL_BIG_ENDIAN
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
CGAL_test_assert(false);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue