| 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; |
| 8 |
|
| 9 |
template <class INT> |
| 10 |
class other_endian |
| 11 |
{ |
| 12 |
private: |
| 13 |
|
| 14 |
INT value; |
| 15 |
|
| 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 |
} |
| 27 |
|
| 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 |
} |
| 43 |
|
| 44 |
operator INT() |
| 45 |
{ |
| 46 |
return change_endian(value); |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
template <class INT> |
| 51 |
class same_endian |
| 52 |
{ |
| 53 |
INT value; |
| 54 |
|
| 55 |
public: |
| 56 |
same_endian(const INT i = 0) |
| 57 |
{ |
| 58 |
value = i; |
| 59 |
} |
| 60 |
|
| 61 |
operator INT() |
| 62 |
{ |
| 63 |
return value; |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
int main() { |
| 84 |
other_endian <_eb91_u_int16_t> little_endian_16_bit_int; |
| 85 |
return 0; |
| 86 |
} |