[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnash-dev] Porting gnash to Sun Solaris x86, endianness detection i
Re: [Gnash-dev] Porting gnash to Sun Solaris x86, endianness detection issues.
Wed, 18 Apr 2007 08:03:29 -0600
Martin Guy wrote:
Can you suggest a way to automatically detect endianness on your box
so that we can make a patch that will also work everywhere else?
At 02:03 AM 4/18/2007, James McGill wrote:
const unsigned int IS_LITTLE_ENDIAN_TEST_BIT = 1u;
// If left-most byte of 1 is non-zero, we're little endian
const bool IS_LITTLE_ENDIAN =
*reinterpret_cast<const unsigned char*>(&IS_LITTLE_ENDIAN_TEST_BIT) == 1;
For the record:
This works assuming that sizeof( unsigned char ) < sizeof( unsigned int ),
which isn't true of all implementations any more, given Unicode. Since the
test works for any two discrete, integral types, I'd suggest using 'long',
for safety, or even 'long long', and also including the test
sizeof( A ) < sizeof( B )
to ensure the types really are of different lengths.