Better (in the sense of working) endianness detection.

This commit is contained in:
Sylvain Pion 2006-08-16 15:38:22 +00:00
parent a29fd3cb46
commit fd6524b2fb
2 changed files with 44 additions and 5 deletions

View File

@ -108,14 +108,21 @@ namespace CGAL {
// Big endian or little endian machine.
// ====================================
#include <boost/limits.hpp> // provides endianness macros
#ifdef BOOST_BIG_ENDIAN
// We used to have a config program for this, but it
// is much more convenient to use the preprocessor.
#if defined(__sparc) || defined(__sparc__) \
|| defined(_POWER) || defined(__powerpc__) \
|| defined(__ppc__) || defined(__hppa) \
|| defined(_MIPSEB) || defined(_POWER) \
|| defined(__s390__)
# 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
#else
# error "Unknown endianness"
# error Unknown endianness
#endif

View File

@ -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;
}