FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.robertl / eb91.C
blob3e5ac2b505c6d900e5a1e0ae1bd0b1f4c2420203
1 #include <sys/types.h>
2 #include <algorithm>
3 typedef short _eb91_int16_t;
4 typedef char _eb91_int8_t;
5 typedef unsigned char _eb91_u_int8_t;
6 typedef unsigned short _eb91_u_int16_t;
8 template <class INT>
9 class other_endian
11 private:
12    
13   INT value;
15    
16   _eb91_u_int16_t change_endian(_eb91_u_int16_t x)
17   {
18     union {
19       _eb91_u_int16_t i;
20       _eb91_u_int8_t c[2];
21     } val;
22     val.i = x;
23     std::swap(val.c[0], val.c[1]);
24     return val.i;
25   };
27   _eb91_int16_t change_endian(_eb91_int16_t x)
28   {
29     union {
30       _eb91_int16_t i;
31       _eb91_int8_t c[2];
32     } val;
33     val.i = x;
34     std::swap(val.c[0], val.c[1]);
35     return val.i;
36   };
37 public:
38   other_endian(const INT i = 0)
39   {
40     value = change_endian(i);
41   }
43   operator INT()
44   {
45     return change_endian(value);
46   }
49 template <class INT>
50 class same_endian
52   INT value;
54 public:
55   same_endian(const INT i = 0)
56   {
57     value = i;
58   }
60   operator INT()
61   {
62     return value;
63   }
82 int main() {
83   other_endian <_eb91_u_int16_t> little_endian_16_bit_int;
84   return 0;