]> git.mxchange.org Git - simgear.git/blob - simgear/io/lowtest.cxx
Tweaks to endianess support.
[simgear.git] / simgear / io / lowtest.cxx
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <simgear/compiler.h>
6
7 #include STL_IOSTREAM
8 #include "lowlevel.hxx"
9
10 static const int sgEndianTest = 1;
11 #define sgIsLittleEndian (*((char *) &sgEndianTest ) != 0)
12 #define sgIsBigEndian    (*((char *) &sgEndianTest ) == 0)
13
14
15 int main() {
16     cout << "This machine is ";
17     if ( sgIsLittleEndian ) {
18         cout << "little ";
19     } else {
20         cout << "big ";
21     }
22     cout << "endian" << endl;
23
24     short s = 1111;
25     cout << "short s = " << s << endl;
26     sgEndianSwap((unsigned short *)&s);
27     cout << "short s = " << s << endl;
28     sgEndianSwap((unsigned short *)&s);
29     cout << "short s = " << s << endl;
30
31     int i = 1111111;
32     cout << "int i = " << i << endl;
33     sgEndianSwap((unsigned int *)&i);
34     cout << "int i = " << i << endl;
35     sgEndianSwap((unsigned int *)&i);
36     cout << "int i = " << i << endl;
37
38     double x = 1111111111;
39     cout << "double x = " << x << endl;
40     sgEndianSwap((unsigned long long *)&x);
41     cout << "double x = " << x << endl;
42     sgEndianSwap((unsigned long long *)&x);
43     cout << "double x = " << x << endl;
44 }