StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StArchInfo.cxx
1 
9 #include "StArchInfo.h"
10 
11 #include <iostream>
12 using namespace std;
13 
14 
17 {
18  // init vars
19  fEndian = 0;
20 }
21 
24 {
25  // nothing for now
26 }
27 
28 
31 {
32  return (Endian() == __BIG_ENDIAN);
33 }
34 
37 {
38  return (Endian() == __LITTLE_ENDIAN);
39 }
40 
41 
42 /*
43  * Returns predefined Endianess as 1234 for little and 4321 for big
44  * This does not treat middle-endian.
45  *
46  * Base principle: we use an array of two char (1 byte ecah) and force cast to
47  * a short value and test.
48  *
49  * If the system is little-endian, the 0 and 1 is interpreted
50  * backwards and seen as if it is 0,1. Since the high byte is 0, it
51  * doesn't matter and the low byte is 1, so x is equal to 1.
52  *
53  * If it's a big-endian system, the high byte is 1.
54  *
55  *
56  */
57 Int_t StArchInfo::Endian()
58 {
59 
60  if ( fEndian == 0){
61  // avoid using int32 to char but use instead short versus
62  // unsigned char trick likely more robust
63  unsigned char endian[2] = {1, 0};
64  short x;
65 
66  x = * ((short *) endian);
67 
68  if ( x == 1) {
69  // little
70  fEndian = __LITTLE_ENDIAN;
71  } else {
72  // big or middle
73  fEndian = __BIG_ENDIAN;
74 
75  //
76  // One possible problem ... We do not detect middle-edian
77  // This test ould need to be extended for middle-edian arch (rare)
78  //
79  }
80 
81  }
82  return fEndian;
83 }
Bool_t isBigEndian()
Returns true/false if endianess is/ins&#39;t Big.
Definition: StArchInfo.cxx:30
StArchInfo()
Constructor, initialize variables.
Definition: StArchInfo.cxx:16
Bool_t isLittleEndian()
Returns true/false if endianess is/ins&#39;t Little.
Definition: StArchInfo.cxx:36
~StArchInfo()
Destructore - NOOP.
Definition: StArchInfo.cxx:23