From 1120d5def11ff3804f61ecb05404cef5511474a9 Mon Sep 17 00:00:00 2001 From: aszostak Date: Fri, 9 May 2008 12:56:30 +0000 Subject: [PATCH 1/1] Detecting endianess of platform at runtime and generating warning if not on a little endian machine. --- HLT/MUON/utils/dHLTdumpraw.cxx | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/HLT/MUON/utils/dHLTdumpraw.cxx b/HLT/MUON/utils/dHLTdumpraw.cxx index 81891062de8..ad82fd84f51 100644 --- a/HLT/MUON/utils/dHLTdumpraw.cxx +++ b/HLT/MUON/utils/dHLTdumpraw.cxx @@ -36,15 +36,6 @@ #include "AliHLTMUONUtils.h" -/*TODO: fix this. Need a platform independant way of checking the endian encoding. - * This does not want to work on Apple Mac OS compiler: i686-apple-darw - * Handle this with #ifdef __APPLE__ ? -#include -#ifndef LITTLE_ENDIAN -#error Handling of internal data for non little endian machines not yet implemented. -#endif -*/ - #include #include #include @@ -1326,6 +1317,30 @@ int ParseCommandLine( int main(int argc, const char** argv) { + // Test endianess of this machine during runtime and print warning if it is not + // little endian. + union + { + int dword; + char byte[4]; + } endianTest; + endianTest.dword = 0x1; + if (endianTest.byte[0] != 0x1) + { + cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl; + cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl; + cerr << "!! !!" << endl; + cerr << "!! This is not a little endian machine, but dHLT raw data is normally !!" << endl; + cerr << "!! generated in little endian format. Unless you are looking at localy !!" << endl; + cerr << "!! created simulated data, then this program will not show you correct !!" << endl; + cerr << "!! output. !!" << endl; + cerr << "!! !!" << endl; + cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl; + cerr << "!!!! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !!!!!" << endl; + cerr << endl; + } + + int numOfFiles = 0; bool continueParse = false; int returnCode = EXIT_SUCCESS; -- 2.39.3