00001 #include <simgear/compiler.h> 00002 00003 #include <iostream> 00004 #include "lowlevel.hxx" 00005 00006 00007 static const int sgEndianTest = 1; 00008 #define sgIsLittleEndian (*((char *) &sgEndianTest ) != 0) 00009 #define sgIsBigEndian (*((char *) &sgEndianTest ) == 0) 00010 00011 using std::cout; 00012 using std::endl; 00013 00014 00015 int main() { 00016 cout << "This machine is "; 00017 if ( sgIsLittleEndian ) { 00018 cout << "little "; 00019 } else { 00020 cout << "big "; 00021 } 00022 cout << "endian" << endl; 00023 00024 cout << "sizeof(short) = " << sizeof(short) << endl; 00025 00026 short s = 1111; 00027 cout << "short s = " << s << endl; 00028 sgEndianSwap((uint16_t *)&s); 00029 cout << "short s = " << s << endl; 00030 sgEndianSwap((uint16_t *)&s); 00031 cout << "short s = " << s << endl; 00032 00033 int i = 1111111; 00034 cout << "int i = " << i << endl; 00035 sgEndianSwap((uint32_t *)&i); 00036 cout << "int i = " << i << endl; 00037 sgEndianSwap((uint32_t *)&i); 00038 cout << "int i = " << i << endl; 00039 00040 double x = 1111111111; 00041 cout << "double x = " << x << endl; 00042 sgEndianSwap((uint64_t *)&x); 00043 cout << "double x = " << x << endl; 00044 sgEndianSwap((uint64_t *)&x); 00045 cout << "double x = " << x << endl; 00046 }