2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.robertl / eb91.C
blobbcd3a3dba85a8d5bdd2601962c17b55d362598b6
1 // { dg-do run  }
2 #include <sys/types.h>
3 #include <algorithm>
4 typedef short _eb91_int16_t;
5 typedef char _eb91_int8_t;
6 typedef unsigned char _eb91_u_int8_t;
7 typedef unsigned short _eb91_u_int16_t;
9 template <class INT>
10 class other_endian
12 private:
13    
14   INT value;
16    
17   _eb91_u_int16_t change_endian(_eb91_u_int16_t x)
18   {
19     union {
20       _eb91_u_int16_t i;
21       _eb91_u_int8_t c[2];
22     } val;
23     val.i = x;
24     std::swap(val.c[0], val.c[1]);
25     return val.i;
26   };
28   _eb91_int16_t change_endian(_eb91_int16_t x)
29   {
30     union {
31       _eb91_int16_t i;
32       _eb91_int8_t c[2];
33     } val;
34     val.i = x;
35     std::swap(val.c[0], val.c[1]);
36     return val.i;
37   };
38 public:
39   other_endian(const INT i = 0)
40   {
41     value = change_endian(i);
42   }
44   operator INT()
45   {
46     return change_endian(value);
47   }
50 template <class INT>
51 class same_endian
53   INT value;
55 public:
56   same_endian(const INT i = 0)
57   {
58     value = i;
59   }
61   operator INT()
62   {
63     return value;
64   }
83 int main() {
84   other_endian <_eb91_u_int16_t> little_endian_16_bit_int;
85   return 0;