Skip to content
Snippets Groups Projects
Commit b5dbd26d authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

follow the advice of Lars for checking endian

parent 91ad292d
No related branches found
No related tags found
No related merge requests found
...@@ -19,11 +19,11 @@ namespace BaseLib ...@@ -19,11 +19,11 @@ namespace BaseLib
/// return if this system supports little endian or not /// return if this system supports little endian or not
inline bool IsLittleEndian() inline bool IsLittleEndian()
{ {
int x = 0x00000001; #ifdef ENDIAN_IS_BIG
if (*(char*)&x) return false;
return true; //am little #elif ENDIAN_IS_LITTLE
else return true;
return false; //am big #endif
} }
} }
......
/**
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* \file TestSystemTools.cpp
*
* Created on 2012-10-30 by Norihiro Watanabe
*/
// ** INCLUDES **
#include "gtest.h"
#include "SystemTools.h"
TEST(BaseLib, EndianLittle) {
bool isLittle = false;
int x = 0x00000001;
if (*(char*)&x)
isLittle = true; //am little
ASSERT_EQ (isLittle, BaseLib::IsLittleEndian());
}
...@@ -14,4 +14,16 @@ ELSE() ...@@ -14,4 +14,16 @@ ELSE()
SET( HAVE_64_BIT 1 ) SET( HAVE_64_BIT 1 )
ADD_DEFINITIONS(-DHAVE_64_BIT) ADD_DEFINITIONS(-DHAVE_64_BIT)
SET( BITS 64) SET( BITS 64)
ENDIF() ENDIF()
\ No newline at end of file
# Check endian of the system
INCLUDE (TestBigEndian)
TEST_BIG_ENDIAN (IS_BIG_ENDIAN)
IF (IS_BIG_ENDIAN)
ADD_DEFINITIONS(-DENDIAN_IS_BIG)
# cannot use BIG_ENDIAN because it's reserved in Linux
ELSE ()
ADD_DEFINITIONS(-DENDIAN_IS_LITTLE)
# cannot use LITTLE_ENDIAN because it's reserved in Linux
ENDIF () # IS_BIG_ENDIAN
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment