title: C++ Unions Internals
body: <p>I'm trying to learn mor eabout C++ and ran into some code in a chess program that I need help understanding. I have a union such as:</p>
  
  <pre><code>union b_union {
  
      Bitboard b;
      struct {
      #if defined (BIGENDIAN)
          uint32_t h;
          uint32_t l;
      #else
          uint32_t l;
          uint32_t h;
      #endif
      } dw;
  };
  </code></pre>
  
  <p>The above code falls into the else condition.</p>
  
  <p>Bitboard is defined as uint64_t. If I have a value let's say 0x0025f780, which is 282578800148862, and I set union.b = 0x0025f780, then union.dw.l is updated to 16843134 and union.dw.h is updated to 65793. Intitially l and h start off with 3435973836. Internally, what happened? I'm fairly new to C++. Just trying to wrap my head around unions in how they work internally.</p>
  
  <p>Thanks much for any insights. </p>
  
  <p>David</p>