|
Boost : |
From: Miki Jovanovic (miki_at_[hidden])
Date: 2000-03-10 17:19:24
Oh, I don't know if anyone needs this piece of code, but it will detect
at runtime if your machine is little or big endian...
bool isLittleEndian() {
int temp = 1;
return (*(char*)&temp) != 0;
}
If we adopted a big/little endian template, we might need this. Again,
if anyone is interested, I have this piece of code in my current
project, which combines defines and active detection. It should be
expanded to more platforms for completeness sake.
#if defined(_M_IX86) || defined(_M_PPC)
# define IS_LITTLE_ENDIAN true
# define LITTLE_ENDIAN
# undef BIG_ENDIAN
#elif defined(_M_ALPHA) || defined(_M_MRX000)
# define IS_LITTLE_ENDIAN false
# undef LITTLE_ENDIAN
# define BIG_ENDIAN
#else
# pragma message( "WARNING: Using active endian detection. Performance
warning." )
# pragma message( "WARNING: No endian defines were made. Some code
might be incomplete." )
bool g_isLittleEndian() {
int temp = 1;
return (*(char*)&temp) != 0;
}
# define IS_LITTEL_ENDIAN g_isLittleEndian()
#endif
Cheers,
Miki.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk