/*============================================================================= Name: cvtMacr.h Abs: macro to find out if architecture is little endian for the the slc-aware IOC. The macro is used by slcExec to set a global slcIocIsLittleEndian - which in turn is used by many conversion utilities. Auth: 09-oct-2004 Diane Fairley (DFAIRLEY) lifted from Till Straumann's $EPICS_SITE/src/utils/basicIoOps.h Rev: 02 feb 2005 Debbie Rogind -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 09-dec-2004, diane fairley (dfairley): added this header =============================================================================*/ #ifndef cvtMacr_H #define cvtMacr_H /* Union type to probe endianness; * Access a chunk of data either as a byte stream * or as a int. * * The idea is to use a constant * * EndianTestU endianTester; * * initialized to * * endianTester.i=1; * * and subsequentially probing it: * * if (endianTester.c[0]) { * its_little_endian(); * } else { * its_big_endian(); * } * * Ideally, the compiler performs this check and * optimizes out the unused code (including the check itself) * * I found that this works e.g. with the solaris compiler * GCC needs additional help, however. */ typedef union { int i; char c[sizeof(int)]; } __EndianTestU; #ifdef __GNUC__ #define _INLINE_ __inline__ /* we have inline feature */ /* GCC doesn't optimize a static const variable away :-( * we may cast unions, however and this works fine */ #if 0 #define ENDIAN_TEST_IS_LITTLE (((__EndianTestU){1}).c[0]) #else static __inline__ int __endian_test_is_little(void) { const __EndianTestU u = {(int)1}; return u.c[0]; } #define ENDIAN_TEST_IS_LITTLE __endian_test_is_little() #endif #else /* not gcc */ #define _INLINE_ /* has probably no inline feature * NOTE: this may lead to instantiation of these routines * in every object file which uses this header! * Using other compilers than gcc is only supported * for testing... */ static const __EndianTestU endianTester={(int)1}; #define ENDIAN_TEST_IS_LITTLE (endianTester.c[0]) #endif /* if __GNUC__ */ #endif /*cvtMacr_H*/